Skip to content

Fix str_title_case skipping later lowercase-exception words after a leading occurrence#371

Merged
jkwill87 merged 1 commit into
jkwill87:mainfrom
patchwright:fix-title-case-repeated-exception
Jul 11, 2026
Merged

Fix str_title_case skipping later lowercase-exception words after a leading occurrence#371
jkwill87 merged 1 commit into
jkwill87:mainfrom
patchwright:fix-title-case-repeated-exception

Conversation

@patchwright

Copy link
Copy Markdown
Contributor

Problem

In str_title_case, the lowercase-exception pass bails out of the whole
loop the first time a match is found at the start of the string:

for pos in findall(string_lower, exception):
    is_start = pos < 2
    if is_start:
        break        # aborts every remaining occurrence of this word

findall yields every position of the exception word. The intent of the
is_start guard is to leave the leading word capitalized — but break
abandons all later occurrences too, so a small word that appears once at the
start and again later never gets lowercased:

>>> from mnamer.utils import str_title_case
>>> str_title_case("the cat in the hat")
'The Cat in The Hat'      # expected: 'The Cat in the Hat'
>>> str_title_case("a man and a plan")
'A Man and A Plan'        # expected: 'A Man and a Plan'

Fix

Use continue instead of break, so only the leading occurrence is skipped
and later ones are still processed. One-word change.

Tests

Added test_str_title_case__lower__repeated_after_start covering a
lowercase-exception word that recurs after the start (the cat in the hat,
its uppercase variant, and a man and a plan). Verified it fails on the
previous code and passes with the fix. The full local suite (347 tests)
passes, and ruff check / ruff format --check are clean.

The lowercase-exception pass used `break` when an exception word matched
at the start of the string, which abandoned every *later* occurrence of
that word instead of just the leading one. A small word appearing once at
the start and again later was therefore never lowercased:

    str_title_case('the cat in the hat')  -> 'The Cat in The Hat'
    str_title_case('a man and a plan')    -> 'A Man and A Plan'

Use `continue` so only the leading occurrence is skipped. Adds a
regression test covering a lowercase-exception word that recurs after the
start (verified to fail on the previous code and pass with the fix).
@patchwright

Copy link
Copy Markdown
Contributor Author

Hi, gentle nudge on this one in case it's slipped off the radar. It's a small fix for str_title_case skipping later lowercase-exception words after the first, with tests, and CI is green. No rush at all; happy to adjust if anything needs changing.

@jkwill87 jkwill87 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix and explanation @patchwright 🙂

@jkwill87 jkwill87 merged commit 45f4229 into jkwill87:main Jul 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants