Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion inflection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def parameterize(string: str, separator: str = '-') -> str:
if separator:
re_sep = re.escape(separator)
# No more than one of the separator in a row.
string = re.sub(r'%s{2,}' % re_sep, separator, string)
string = re.sub(r'(?:%s){2,}' % re_sep, separator, string)
# Remove leading/trailing separator.
string = re.sub(r"(?i)^{sep}|{sep}$".format(sep=re_sep), '', string)

Expand Down
7 changes: 7 additions & 0 deletions test_inflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,13 @@ def test_parameterize_with_multi_character_separator(
)


def test_parameterize_with_multi_character_separator_partial_collapse() -> None:
# Regression test: multi-character separator should not consume
# non-separator characters that happen to overlap with separator chars.
# '__' is a 2-char separator, so '___' = one separator + one literal '_'.
assert 'test___case' == inflection.parameterize('test___case', '__')


@pytest.mark.parametrize(
("some_string", "parameterized_string"),
STRING_TO_PARAMETERIZE_WITH_NO_SEPARATOR
Expand Down