Allow non-alphanumeric characters in slug

Currently, users are unable to retain non-alphanumeric characters in their URLs unless a substitution specified in their SLUG_SUBSTITUTIONS setting effects a change in their URL. With this change users will be able to use non-alphanumeric characters without having to jump through an extra hoop. This may require a rework (placement into a different setting?) because it will break backwards compatibility for some users who rely on this behavior.
This commit is contained in:
Jason Bohrer 2018-04-16 20:59:24 -04:00 committed by GitHub
commit 61b08fe913
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -299,10 +299,8 @@ def slugify(value, substitutions=()):
for src, dst, skip in substitutions:
orig_value = value
value = value.replace(src.lower(), dst.lower())
# if replacement was made then skip non-alphanum
# replacement if instructed to do so
if value != orig_value:
replace = replace and not skip
# skip non-alphanum replacement if instructed to do so
replace = replace and not skip
if replace:
value = re.sub(r'[^\w\s-]', '', value).strip()