mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
Make sure generated slugs are not empty (#43153)
This commit is contained in:
parent
1433cdaa12
commit
78b057ce02
@ -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:
|
||||||
|
@ -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():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user