From b0e3d5a576f5e00b5a31d3c2a9770a3be383ebaf Mon Sep 17 00:00:00 2001 From: Magnus Ihse Bursie Date: Thu, 17 Nov 2016 00:05:10 +0100 Subject: [PATCH] Better handling of accented characters in slugify (#4399) (#4423) * Better handling of accented characters in slugify (#4399) * Update __init__.py --- homeassistant/util/__init__.py | 3 ++- tests/util/test_init.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/homeassistant/util/__init__.py b/homeassistant/util/__init__.py index de16a2d23d2..6d77f67161d 100644 --- a/homeassistant/util/__init__.py +++ b/homeassistant/util/__init__.py @@ -10,6 +10,7 @@ import random import string from functools import wraps from types import MappingProxyType +from unicodedata import normalize from typing import Any, Optional, TypeVar, Callable, Sequence, KeysView, Union @@ -35,7 +36,7 @@ def sanitize_path(path: str) -> str: def slugify(text: str) -> str: """Slugify a given text.""" - text = text.lower().replace(" ", "_") + text = normalize('NFKD', text).lower().replace(" ", "_") return RE_SLUGIFY.sub("", text) diff --git a/tests/util/test_init.py b/tests/util/test_init.py index 9bfd6ebd6ed..d6d583342d7 100644 --- a/tests/util/test_init.py +++ b/tests/util/test_init.py @@ -30,6 +30,7 @@ class TestUtil(unittest.TestCase): self.assertEqual("test", util.slugify("T-!@#$!#@$!$est")) self.assertEqual("test_more", util.slugify("Test More")) self.assertEqual("test_more", util.slugify("Test_(More)")) + self.assertEqual("test_more", util.slugify("Tèst_Mörê")) def test_repr_helper(self): """Test repr_helper."""