Repository navigation
Fix constant case losing idempotency around digits - #372
Closed
afonsojanu wants to merge 1 commit into
Closed
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
constantCase() (and the other all-caps helpers built on the same
splitter) can produce output that splits differently the second time
it's run. A digit sitting between a lower case letter and an upper
case one was always treated as a word break, even when the "upper
case" side was really just the digit's own word being shouted by a
previous pass.
For example constantCase("foo123bar") correctly returns "FOO123BAR"
as one word, but running constantCase on that result again yields
"FOO123_BAR" because the regex now sees a digit directly followed by
an upper case letter and assumes a new word started there. Same story
for "a1b2c3" -> "A1B2C3" -> "A1_B2_C3".
The fix only treats a digit->upper transition as a genuine word
boundary when the upper case letter is itself followed by a lower
case letter, which is what happens for a real new word like the "T"
in "V1Test" but not for an already-shouted run like "FOO123BAR".
Verified against the existing suite (28/28 in the change-case package,
141/141 across the monorepo) and a 200k-iteration fuzz pass that found
zero remaining idempotency violations for constantCase.
Added a regression test covering both examples from the bug report.
Author
|
Closing this for now as part of a clean slate — stepping back from everything I had open across these repos. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
constantCase(and any of the other helpers that route through the same wordsplitter, e.g.
capitalCase,snakeCase,dotCase...) can lose its ownoutput the second time it runs.
The splitter's
SPLIT_LOWER_UPPER_REtreats any digit directly followed byan upper case letter as a word break, regardless of what's before the digit.
That's fine the first time (there's no upper case letter in
foo123bartobegin with), but once a word has been shouted into all caps, the same digit
is now followed by an upper case letter purely as an artifact of that
shouting, not because a new word actually started there, so re-splitting
inserts a bogus boundary.
I confirmed this against the reported repro and then fuzzed
constantCaseagainst 200k random ASCII strings comparing
f(x)tof(f(x)); theunmodified splitter fails on roughly 4% of them, all following this same
digit pattern.
The fix keeps the "digit ends a word" rule, but only when the following
upper case letter is itself the start of a real word, i.e. followed by a
lower case letter (like the
TinV1Test). An already-shouted run such asFOO123BARno longer matches, since the letter after the digit isn'tfollowed by a lower case letter anywhere nearby, it's followed by more
capitals.
With that change the same 200k-iteration fuzz run comes back with zero
constantCasemismatches, the full existing suite still passes (141 testsacross the monorepo, including the
V1Test,TestV2andFoo12019Barcases that specifically exercise digit/case boundaries), and I added a
regression test covering the two examples above.