* Better handling of accented characters in slugify (#4399) * Update __init__.py
This commit is contained in:
parent
f006b00dc1
commit
b0e3d5a576
2 changed files with 3 additions and 1 deletions
|
@ -10,6 +10,7 @@ import random
|
||||||
import string
|
import string
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from types import MappingProxyType
|
from types import MappingProxyType
|
||||||
|
from unicodedata import normalize
|
||||||
|
|
||||||
from typing import Any, Optional, TypeVar, Callable, Sequence, KeysView, Union
|
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:
|
def slugify(text: str) -> str:
|
||||||
"""Slugify a given text."""
|
"""Slugify a given text."""
|
||||||
text = text.lower().replace(" ", "_")
|
text = normalize('NFKD', text).lower().replace(" ", "_")
|
||||||
|
|
||||||
return RE_SLUGIFY.sub("", text)
|
return RE_SLUGIFY.sub("", text)
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class TestUtil(unittest.TestCase):
|
||||||
self.assertEqual("test", util.slugify("T-!@#$!#@$!$est"))
|
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("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):
|
def test_repr_helper(self):
|
||||||
"""Test repr_helper."""
|
"""Test repr_helper."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue