Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringUtils.ToSnakeCase fails for many common scenarios #1956

Open
rowandh opened this issue Jan 10, 2019 · 2 comments
Open

StringUtils.ToSnakeCase fails for many common scenarios #1956

rowandh opened this issue Jan 10, 2019 · 2 comments

Comments

@rowandh
Copy link

rowandh commented Jan 10, 2019

StringUtils.ToSnakeCase (used by SnakeCaseNamingStrategy) fails to correctly snake case several common scenarios.

There's plenty more examples when using unicode characters (due to a lack of unicode support), and non-alphanumeric characters, though I'm unsure whether that's by design so have only included examples using ASCII letters and digits.

Steps to reproduce

Add the tests below to Newtonsoft.Json.Tests.Utilities.ToSnakeCaseTest. Observe the output (seen in the comments) is different to expected.

Assert.AreEqual("ab1", StringUtils.ToSnakeCase("AB1")); // FAILS, produces a_b1
Assert.AreEqual("abc1", StringUtils.ToSnakeCase("ABC1")); // FAILS, produces ab_c1
Assert.AreEqual("abc123d_ef456", StringUtils.ToSnakeCase("ABC123DEf456")); // FAILS, produces ab_c123_d_ef456
Assert.AreEqual("abc123def456", StringUtils.ToSnakeCase("ABC123DEF456")); // FAILS, produces ab_c123_de_f456
@YohDeadfall
Copy link

@JamesNK I can fix it, but and align it with a policy in System.Text.Json (not merged yet).

@jgoyvaerts
Copy link

What's the status of this? StringUtils.ToSnakeCase in it's current version is pretty bad and makes using snake case not a viable option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants