diff --git a/slugify/slugify.py b/slugify/slugify.py index f4e5faf..abfc099 100644 --- a/slugify/slugify.py +++ b/slugify/slugify.py @@ -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__}') diff --git a/test.py b/test.py index fcec4b6..32aa0ab 100644 --- a/test.py +++ b/test.py @@ -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):