diff --git a/CHANGELOG.md b/CHANGELOG.md index 81e1734..2859817 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## Unreleased + +- Docs: an empty `smart_truncate` separator raises `ValueError` only on the word-boundary path; otherwise it is a plain cut. README and legacy docstring corrected, behavior unchanged (reported by Arden). + ## 9.2.0 - Modern mode only: with `allow_unicode=True`, keep combining marks (Unicode Mn/Mc, e.g. vowel signs, viramas, Arabic harakat, Hebrew niqqud) and in-word ZWNJ/ZWJ as part of words instead of splitting at them, fixing slugs for Hindi, Tamil, Bengali, Sinhala, Thai, Khmer, Myanmar, Arabic, Hebrew and other scripts. Output is unchanged for text without combining marks or joiners. Legacy output is unchanged (Nipuna-Lakruwan, #214). diff --git a/README.md b/README.md index f76e613..1fc1721 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` only on the word-boundary path (`word_boundary=True` and the string at least `max_length` long; otherwise it is a plain cut), 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..aaacd98 100644 --- a/slugify/_legacy.py +++ b/slugify/_legacy.py @@ -75,7 +75,9 @@ 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 only on the word-boundary path + (word_boundary=True and the string at least max_length long), as in the + legacy implementation; otherwise it is a plain cut. """ string = string.strip(separator) if not max_length: diff --git a/tests/test_release.py b/tests/test_release.py index 0daccd6..8aae69c 100644 --- a/tests/test_release.py +++ b/tests/test_release.py @@ -225,6 +225,10 @@ def test_truncate_contracts(self): self.assertEqual(smart_truncate('abcdef', -1), 'abcde') with self.assertRaises(ValueError): smart_truncate('abc', 2, True, '') + # An empty separator raises only on the word-boundary path; elsewhere it is a plain cut. + self.assertEqual(smart_truncate('aaa bbb', 3, False, ''), 'aaa') + self.assertEqual(smart_truncate('aaa bbb', 10, True, ''), 'aaa bbb') + self.assertEqual(smart_truncate('aaa bbb', 0, True, ''), 'aaa bbb') self.assertEqual(smart_truncate('oversized a b', 3, True), 'a b') self.assertEqual(smart_truncate('oversized a b', 3, True, save_order=True), 'ove')