diff --git a/pathvalidate/_symbol.py b/pathvalidate/_symbol.py index 29cf608..844da1a 100644 --- a/pathvalidate/_symbol.py +++ b/pathvalidate/_symbol.py @@ -51,8 +51,8 @@ def replace_symbol( exclude_symbols: Symbols that were excluded from the replacement. is_replace_consecutive_chars: - If |True|, replace consecutive multiple ``replacement_text`` characters - to a single character. + If |True|, replace consecutive occurrences of ``replacement_text`` + with a single occurrence. is_strip: If |True|, strip ``replacement_text`` from the beginning/end of the replacement text. @@ -85,7 +85,7 @@ def replace_symbol( return new_text if is_replace_consecutive_chars: - new_text = re.sub(f"{re.escape(replacement_text)}+", replacement_text, new_text) + new_text = re.sub(f"(?:{re.escape(replacement_text)})+", replacement_text, new_text) if is_strip: new_text = new_text.strip(replacement_text) diff --git a/test/test_symbol.py b/test/test_symbol.py index 918f2df..604dddc 100644 --- a/test/test_symbol.py +++ b/test/test_symbol.py @@ -85,6 +85,14 @@ def test_normal_exclude_symbols(self, value, exclude_symbols, expected): ["!a##b$$$c((((d]]]])", "_", True, False, "_a_b_c_d_"], ["!a##b$$$c((((d]]]])", "_", False, True, "a__b___c____d"], ["!a##b$$$c((((d]]]])", "_", False, False, "_a__b___c____d_____"], + ["A!!B", "ab", True, False, "AabB"], + ["A!!B", "[]", True, False, "A[]B"], + ["A!!B", "恂恄", True, False, "A恂恄B"], + ["abbbb", "ab", True, False, "abbbb"], + ["abab", "ab", True, False, "ab"], + ["ababa", "aba", True, False, "ababa"], + ["A!!B", "ab", False, False, "AababB"], + ["A!!B", "", True, False, "AB"], ], ) def test_normal_consecutive(