Skip to content

ToTitleCase capitalizes the letter after a U+2019 apostrophe: "don’t stop" -> "Don’T Stop" #89

Description

@matt-edmondson

What's wrong

Elsewhere the library treats U+2019 (the typographic apostrophe) the same as ASCII ' (see IsApostropheWithinWord and IsWordCharacter). ToTitleCase (CaseConverter/CaseConverter.cs, ~line 322) passes the text to CultureInfo.InvariantCulture.TextInfo.ToTitleCase, and that method only special-cases ASCII '. It treats U+2019 as a word separator and capitalizes the letter after it. The #75 fix therefore covers only the ASCII form.

Observed on main (1c1c555):

  • "don’t stop".ToTitleCase() gives Don’T Stop; expected Don’t Stop
  • "it’s fine" gives It’S Fine
  • "API’s" gives API’S
  • ASCII "don't stop" gives Don't Stop (correct)

Text pasted from word processors, macOS and web pages uses smart quotes by default, so this is easy to hit. Confirmed with a temporary MSTest.

Suggested fix

In ToTitleCase, replace each in-word U+2019 (IsApostropheWithinWord) with ASCII ' before calling TextInfo.ToTitleCase, and put the U+2019 back at the same indices afterwards. ToTitleCase does not change the string's length, so restoring by index is safe.

Acceptance: add "don’t stop" and "it’s fine" rows to the ToTitleCase tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions