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
9 changes: 9 additions & 0 deletions slugify/slugify.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,15 @@ def slugify(
"""
if algorithm not in ('legacy', 'modern'):
raise ValueError("algorithm must be 'legacy' or 'modern'")
# bool is an int subclass: max_length=True previously truncated to 1 char.
if isinstance(max_length, bool) or not isinstance(max_length, int):
raise TypeError(
f"max_length must be an int, not {type(max_length).__name__}"
)
if not isinstance(separator, str):
raise TypeError(
f"separator must be str, not {type(separator).__name__}"
)
if not isinstance(text, str):
if not isinstance(text, (bytes, bytearray)):
raise TypeError(f'text must be str, bytes or bytearray, not {type(text).__name__}')
Expand Down
10 changes: 10 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,16 @@ def test_pre_translation(self):
self.assertEqual(PRE_TRANSLATIONS, [('Ю', 'U'), ('Щ', 'Sch'), ('У', 'Y'), ('Х', 'H'), ('Я', 'Ya'), ('Ё', 'E'), ('ё', 'e'), ('я', 'ya'), ('х', 'h'), ('у', 'y'), ('щ', 'sch'), ('ю', 'u'), ('Ü', 'Ue'), ('Ö', 'Oe'), ('Ä', 'Ae'), ('ä', 'ae'), ('ö', 'oe'), ('ü', 'ue'), ('Ϋ́', 'Y'), ('Ϋ', 'Y'), ('Ύ', 'Y'), ('Υ', 'Y'), ('Χ', 'Ch'), ('χ', 'ch'), ('Ξ', 'X'), ('ϒ', 'Y'), ('υ', 'y'), ('ύ', 'y'), ('ϋ', 'y'), ('ΰ', 'y')])



def test_max_length_rejects_bool(self):
with self.assertRaises(TypeError):
slugify("Hello World", max_length=True)
with self.assertRaises(TypeError):
slugify("Hello World", max_length=1.5)
with self.assertRaises(TypeError):
slugify("Hello", separator=None)
self.assertEqual(slugify("Hello World", max_length=5), "hello")

class TestSlugifyUnicode(unittest.TestCase):
def test_extraneous_seperators(self):

Expand Down