mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix/slugify with german umlaut ss (#7029)
* more tests for slugify * Fix german umlauts in slugify * Update __init__.py
This commit is contained in:
parent
4d9e681fc1
commit
3c35d5ea58
@ -22,6 +22,9 @@ U = TypeVar('U')
|
|||||||
RE_SANITIZE_FILENAME = re.compile(r'(~|\.\.|/|\\)')
|
RE_SANITIZE_FILENAME = re.compile(r'(~|\.\.|/|\\)')
|
||||||
RE_SANITIZE_PATH = re.compile(r'(~|\.(\.)+)')
|
RE_SANITIZE_PATH = re.compile(r'(~|\.(\.)+)')
|
||||||
RE_SLUGIFY = re.compile(r'[^a-z0-9_]+')
|
RE_SLUGIFY = re.compile(r'[^a-z0-9_]+')
|
||||||
|
TBL_SLUGIFY = {
|
||||||
|
ord('ß'): 'ss'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def sanitize_filename(filename: str) -> str:
|
def sanitize_filename(filename: str) -> str:
|
||||||
@ -36,9 +39,13 @@ def sanitize_path(path: str) -> str:
|
|||||||
|
|
||||||
def slugify(text: str) -> str:
|
def slugify(text: str) -> str:
|
||||||
"""Slugify a given text."""
|
"""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:
|
def repr_helper(inp: Any) -> str:
|
||||||
|
@ -37,6 +37,7 @@ class TestUtil(unittest.TestCase):
|
|||||||
util.slugify("greg_phone - exp_wayp1"))
|
util.slugify("greg_phone - exp_wayp1"))
|
||||||
self.assertEqual("we_are_we_are_a_test_calendar",
|
self.assertEqual("we_are_we_are_a_test_calendar",
|
||||||
util.slugify("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):
|
def test_repr_helper(self):
|
||||||
"""Test repr_helper."""
|
"""Test repr_helper."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user