Make sure generated slugs are not empty (#43153)

This commit is contained in:
Thomas Hollstegge 2021-01-27 12:25:49 +01:00 committed by GitHub
parent 1433cdaa12
commit 78b057ce02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -87,7 +87,10 @@ def sanitize_path(path: str) -> str:
def slugify(text: str, *, separator: str = "_") -> str: def slugify(text: str, *, separator: str = "_") -> str:
"""Slugify a given text.""" """Slugify a given text."""
return unicode_slug.slugify(text, separator=separator) if text == "":
return ""
slug = unicode_slug.slugify(text, separator=separator)
return "unknown" if slug == "" else slug
def repr_helper(inp: Any) -> str: def repr_helper(inp: Any) -> str:

View File

@ -68,6 +68,12 @@ def test_slugify():
assert util.slugify("Tèst_äöüß_ÄÖÜ") == "test_aouss_aou" assert util.slugify("Tèst_äöüß_ÄÖÜ") == "test_aouss_aou"
assert util.slugify("影師嗎") == "ying_shi_ma" assert util.slugify("影師嗎") == "ying_shi_ma"
assert util.slugify("けいふぉんと") == "keihuonto" assert util.slugify("けいふぉんと") == "keihuonto"
assert util.slugify("$") == "unknown"
assert util.slugify("") == "unknown"
assert util.slugify("") == "unknown"
assert util.slugify("$$$") == "unknown"
assert util.slugify("$something") == "something"
assert util.slugify("") == ""
def test_repr_helper(): def test_repr_helper():