Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
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` 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
Expand Down
4 changes: 3 additions & 1 deletion slugify/_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions tests/test_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down