Skip to content

Commit f6f76ae

Browse files
derek73claude
andcommitted
fix: narrow space-before-punctuation regex to commas only
; and : have no known use case in name string_format patterns. Matching only \s+, keeps the fix scoped to the reported issue. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent be73bba commit f6f76ae

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

nameparser/config/regexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
("period_not_at_end",re.compile(r'.*\..+$', re.I | re.U)),
2323
("emoji",re_emoji),
2424
("phd", re.compile(r'\s(ph\.?\s+d\.?)', re.I | re.U)),
25-
("space_before_punct", re.compile(r'\s+([,;:])', re.U)),
25+
("space_before_comma", re.compile(r'\s+,', re.U)),
2626
])
2727
"""
2828
All regular expressions used by the parser are precompiled and stored in the config.

nameparser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __str__(self) -> str:
189189
_s = self.string_format.format(**self.as_dict())
190190
# remove trailing punctuation from missing nicknames
191191
_s = _s.replace(str(self.C.empty_attribute_default), '').replace(" ()", "").replace(" ''", "").replace(' ""', "")
192-
_s = self.C.regexes.space_before_punct.sub(r'\1', _s)
192+
_s = self.C.regexes.space_before_comma.sub(',', _s)
193193
return self.collapse_whitespace(_s).strip(', ')
194194
return " ".join(self)
195195

0 commit comments

Comments
 (0)