Skip to content

Possessive all-caps words are split mid-word: "CEO's office".ToSnakeCase() -> "ce_os_office", "API's".ToPascalCase() -> "ApIs" #88

Description

@matt-edmondson

What's wrong

Since the #83 fix (5c15077), ReplaceNonAlphaNumericWithSpace drops an apostrophe that sits inside a word, so "CEO's" becomes "CEOs" before SplitOnCaseChange runs. IsWordBoundary has an acronym-tail rule (upper, upper, lower), and it now breaks before the last capital, which gives "CE Os".

Observed on main (1c1c555):

Input Method Actual Expected
CEO's office ToSnakeCase ce_os_office ceos_office
the CEO's office ToPascalCase TheCeOsOffice TheCeosOffice
API's ToPascalCase / ToCamelCase ApIs / apIs Apis / apis
API's ToSnakeCase / ToMacroCase ap_is / AP_IS apis / APIS
NASA's mission ToSnakeCase nas_as_mission nasas_mission

The typographic apostrophe U+2019 behaves the same way. Lowercase input works: "ceo's" gives ceos. Before 5c15077 the output was ceo_s, which was less damaging, so this is a regression on a very common input: possessive acronyms. Confirmed with a temporary MSTest and a console probe.

Suggested fix

Take either approach:

  • Run the case-change split while the apostrophe is still in the text, then drop the apostrophe. IsWordBoundary already refuses to break at don'T.
  • Or lowercase an all-caps run that is followed by an in-word apostrophe and letters, so CEO's is handled like ceo's.

Acceptance: add regression rows for API's, CEO's office and NASA's mission across Pascal, Camel, Snake, Kebab and Macro.

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