diff --git a/slugify/slugify.py b/slugify/slugify.py index 9b5f27f..54843b6 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -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: diff --git a/test.py b/test.py index fcec4b6..743a6df 100644 --- a/test.py +++ b/test.py @@ -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