Skip to content

All-caps input: apostrophe-second names come out as d'ARTEMIS / O'BRIEN instead of d'Artemis / O'Brien #105

Open

Description

@rahul05ranjan

Passing all-caps headlines through titlecase() produces visibly broken mixed-case output for names with a leading-apostrophe second letter:

>>> from titlecase import titlecase
>>> titlecase("D'ARTEMIS OF LONDON")
"d'ARTEMIS of London"
>>> titlecase("O'BRIEN AND D'ARCY")
"O'BRIEN and d'ARCY"

Every other word in the sentence gets normalized and re-cased (OF LONDON → of London), but these words come out as d'ARTEMIS / O'BRIEN — half original-caps, half lowercased, neither correct.

The APOS_SECOND branch fires before the all-caps line is normalized, and it only ever changes word[0] and the letter right after the apostrophe (word[2]), appending the rest of the word unchanged:

if APOS_SECOND.match(word):
    if len(word[0]) == 1 and word[0] not in 'aeiouAEIOU':
        word = word[0].lower() + word[1] + word[2].upper() + word[3:]
    else:
        word = word[0].upper() + word[1] + word[2].upper() + word[3:]

So for all-caps input D'ARTEMIS the tail RTEMIS keeps its shouted caps, and for O'BRIEN the consonant/vowel test picks the word[0].upper() path and the whole word stays uppercase. Mixed-case input like d'artemis of london works fine (d'Artemis of London), so this is specific to all-caps lines, which elsewhere are assumed to carry no intentional casing.

PR #101 previously described this (for O'BRIEN'S HOUSE IS FOR SALE / D'ARTAGNAN AND THE THREE MUSKETEERS) but was closed unmerged, so the bug is still live on main.

One possible fix is to lowercase the word first when all_caps is true, before applying the apostrophe handling — then the existing APOS_SECOND transform produces d'Artemis / O'Brien.

Tested on 2.4.1 / current main.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions