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
3 changes: 2 additions & 1 deletion slugify/slugify.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def smart_truncate(
if len(string) < max_length:
return string

if not word_boundary:
# Empty separator cannot split words; fall back to hard truncate.
if not word_boundary or not separator:
return string[:max_length].strip(separator)

if separator not in string:
Expand Down
11 changes: 11 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,17 @@ def test_smart_truncate_no_seperator(self):
r = smart_truncate(txt, max_length=100, separator='_')
self.assertEqual(r, txt)

def test_smart_truncate_empty_separator_word_boundary(self):
txt = 'helloworld'
self.assertEqual(
smart_truncate(txt, max_length=5, word_boundary=True, separator=''),
'hello',
)
self.assertEqual(
slugify('hello world', max_length=5, word_boundary=True, separator=''),
'hello',
)


PY3 = sys.version_info.major == 3

Expand Down