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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion slugify/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading