diff --git a/README.md b/README.md index 2a68581..3e522db 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ slugify( - `backend`: select a backend from the table above. Ignored for transliteration in Unicode mode, but still validated. `smart_truncate(string, max_length=0, word_boundary=False, separator=' ', save_order=False)` -is also public and retains legacy behavior: `str.strip(separator)` strips a character set, empty separators raise `ValueError`, zero is unlimited, and negative limits retain slicing semantics. Modern slugify uses a separate private token-budget helper; it does not change this public function. +is also public and retains legacy behavior: `str.strip(separator)` strips a character set, an empty separator raises `ValueError` when word-boundary truncation reaches the split step (the hard-cut path does not raise), zero is unlimited, and negative limits retain slicing semantics. Modern slugify uses a separate private token-budget helper; it does not change this public function. ```python from slugify import slugify diff --git a/slugify/_legacy.py b/slugify/_legacy.py index c0dfd67..158da86 100644 --- a/slugify/_legacy.py +++ b/slugify/_legacy.py @@ -75,7 +75,8 @@ def smart_truncate( """Historical public truncation behavior, including character-set stripping. Zero means unlimited; negative limits retain Python slicing semantics. - An empty separator raises ValueError, as in the legacy implementation. + An empty separator raises ValueError when word-boundary truncation splits + the string; the hard-cut path does not raise for an empty separator. """ string = string.strip(separator) if not max_length: diff --git a/tests/test_release.py b/tests/test_release.py index 0daccd6..4a89b14 100644 --- a/tests/test_release.py +++ b/tests/test_release.py @@ -19,6 +19,12 @@ class ReleaseRegressionTests(unittest.TestCase): + def test_smart_truncate_empty_separator_only_raises_on_word_boundary_path(self): + with self.assertRaisesRegex(ValueError, 'empty separator'): + smart_truncate('a b c', 3, word_boundary=True, separator='') + self.assertEqual( + smart_truncate('a b c', 3, word_boundary=False, separator=''), 'a b') + def test_legacy_goldens_and_differential(self): from tools import legacy_reference from tools.check_algorithms import check_differential, check_goldens