Better handling of accented characters in slugify (#4399) (#4423)

* Better handling of accented characters in slugify (#4399)

* Update __init__.py
This commit is contained in:
Magnus Ihse Bursie 2016-11-17 00:05:10 +01:00 committed by Paulus Schoutsen
parent f006b00dc1
commit b0e3d5a576
2 changed files with 3 additions and 1 deletions

View File

@ -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)

View File

@ -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."""