-
Notifications
You must be signed in to change notification settings - Fork 967
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
Unexpected behaviour in certain cases for .Dehumanize() #1102
Comments
Could you check if the string contains any spaces to avoid dehumanizing this case? The dehumanize method doesn't allow any customization (as far as I can see), and basically tries to title-case every word in the input string: Humanizer/src/Humanizer/StringDehumanizeExtensions.cs Lines 17 to 18 in 5c3b134
|
The problem here is with conjunctions or similar words (like And, Or, Of, But, A, Yet, Nor, So, As, etc), which don't get capitalized correctly. So the code should be changed to the following (or something faster): The test method (CanDehumanizeIntoAPascalCaseWord) in StringDehumanizeTests.cs show that the intention was to indeed pascalize the output, and not just use Titlecase and it's quirks. As it stands the method even fails to Dehumanize/Pascalize 'CanDehumanizeIntoAPascalCaseWord' correctly to 'CanDehumanizeIntoAPascalCaseWord', because the 'A' gets unexpectedly lowercased. I would suggest adding the following tests (and fixing references to camalized): |
…o expanded the tests to catch these edge cases
I've submitted the following PR to fix this problem: |
I've already completed my PR, but I'd suggest adding these two tests too: |
As far as I understand it the string "ListOfProducts" is already Dehumanized, so calling .Dehumanize() should basically have no effect, i.e. the output should equal the input in these cases.
However "ListOfProducts".Dehumanize() currently returns "ListofProducts" - The "Of" part got changed to "of" for some reason.
For more info, I would expect the output of the following lines to be exactly the same (i.e "ListOfProducts"):
var output1 = "List of products".Dehumanize();
var output2 = "List of products".Dehumanize().Dehumanize();
var output3 = "List of products".Dehumanize().Dehumanize().Dehumanize();
This unexpected change of casing is currently causing my software to break, because sometimes I'm forced to combine and therefore reprocess parts of a string in another part of my software, and the change of casing causes equality errors.
I'm using it to lookup class Types so the casing really matters, and I'm not sure how to work around the problem just yet.
The text was updated successfully, but these errors were encountered: