Skip to content
New issue

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

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

Already on GitHub? # to your account

Humanize(), ApplyCase(), and Transform() all produce incorrect result when the input is in UPPERCASE #1557

Open
ICloneableX opened this issue Dec 21, 2024 · 1 comment

Comments

@ICloneableX
Copy link

ICloneableX commented Dec 21, 2024

A similar issue has been raised before (in #1050) but was only fixed for one or two isolated cases. Several other cases are affected by this. Consider the following code:

var inputs = new[] { "WORD", "SPACE SEPARATOR", "HYPEN-SEPARATOR" };
foreach (string input in inputs)
{
    Console.WriteLine("Humanize>Title: ".PadRight(20) + input + " --> " + input.Humanize(LetterCasing.Title));
    Console.WriteLine("Humanize>Sentence: ".PadRight(20) + input + " --> " + input.Humanize(LetterCasing.Sentence));
    Console.WriteLine("ApplyCase>Title: ".PadRight(20) + input + " --> " + input.ApplyCase(LetterCasing.Title));
    Console.WriteLine("ApplyCase>Sentence: ".PadRight(20) + input + " --> " + input.Humanize(LetterCasing.Sentence));
    Console.WriteLine("Transform>Title: ".PadRight(20) + input + " --> " + input.Transform(To.TitleCase));
    Console.WriteLine("Transform>Sentence: ".PadRight(20) + input + " --> " + input.Transform(To.SentenceCase));
}

Output:

Humanize>Title:     WORD --> WORD ❌
Humanize>Sentence:  WORD --> WORD ❌
ApplyCase>Title:    WORD --> WORD ❌
ApplyCase>Sentence: WORD --> WORD ❌
Transform>Title:    WORD --> WORD ❌
Transform>Sentence: WORD --> WORD ❌
Humanize>Title:     SPACE SEPARATOR --> Space Separator ✔
Humanize>Sentence:  SPACE SEPARATOR --> Space separator ✔
ApplyCase>Title:    SPACE SEPARATOR --> SPACE SEPARATOR ❌
ApplyCase>Sentence: SPACE SEPARATOR --> Space separator ✔
Transform>Title:    SPACE SEPARATOR --> SPACE SEPARATOR ❌
Transform>Sentence: SPACE SEPARATOR --> SPACE SEPARATOR ❌
Humanize>Title:     HYPEN-SEPARATOR --> HYPEN SEPARATOR ❌
Humanize>Sentence:  HYPEN-SEPARATOR --> HYPEN SEPARATOR ❌
ApplyCase>Title:    HYPEN-SEPARATOR --> HYPEN-SEPARATOR ❌
ApplyCase>Sentence: HYPEN-SEPARATOR --> HYPEN SEPARATOR ❌
Transform>Title:    HYPEN-SEPARATOR --> HYPEN-SEPARATOR ❌
Transform>Sentence: HYPEN-SEPARATOR --> HYPEN-SEPARATOR ❌

Tested on Humanizer.Core 2.14.1.

@leus
Copy link

leus commented Jan 23, 2025

I think the cases you see as correct are actually wrong. Uppercase words are upper for a reason, I don't want UN to be spelled "Un" in a title.

If you need Title Case and don't mind about uppercase, then do something like source.ToLowerInvariant().Humanize(LetterCasing.Title)).

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

No branches or pull requests

2 participants