diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index 6d77f67161d..1186892b512 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -22,6 +22,9 @@ U = TypeVar('U') RE_SANITIZE_FILENAME = re.compile(r'(~|\.\.|/|\\)') RE_SANITIZE_PATH = re.compile(r'(~|\.(\.)+)') RE_SLUGIFY = re.compile(r'[^a-z0-9_]+') +TBL_SLUGIFY = { + ord('ß'): 'ss' +} def sanitize_filename(filename: str) -> str: @@ -36,9 +39,13 @@ def sanitize_path(path: str) -> str: def slugify(text: str) -> str: """Slugify a given text.""" - text = normalize('NFKD', text).lower().replace(" ", "_") + text = normalize('NFKD', text) + text = text.lower() + text = text.replace(" ", "_") + text = text.translate(TBL_SLUGIFY) + text = RE_SLUGIFY.sub("", text) - return RE_SLUGIFY.sub("", text) + return text def repr_helper(inp: Any) -> str: diff --git a/tests/util/test_init.py b/tests/util/test_init.py index 3ccb72920d4..ba8415d597f 100644 --- a/tests/util/test_init.py +++ b/tests/util/test_init.py @@ -37,6 +37,7 @@ class TestUtil(unittest.TestCase): util.slugify("greg_phone - exp_wayp1")) self.assertEqual("we_are_we_are_a_test_calendar", util.slugify("We are, we are, a... Test Calendar")) + self.assertEqual("test_aouss_aou", util.slugify("Tèst_äöüß_ÄÖÜ")) def test_repr_helper(self): """Test repr_helper."""