diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 3388aabeb80..068ee48ff4f 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -43,7 +43,7 @@ def _guess_mimetype(ext=False, default='text/html'): return ext is not False and exts.get(ext, default) or exts -def slugify_one(s, max_length=None): +def slugify_one(s, max_length=0): """ Transform a string to a slug that can be used in a url path. This method will first try to do the job with python-slugify if present. Otherwise it will process string by stripping leading and ending spaces, @@ -61,13 +61,12 @@ def slugify_one(s, max_length=None): except TypeError: pass uni = unicodedata.normalize('NFKD', s).encode('ascii', 'ignore').decode('ascii') - slug_str = re.sub('[\W_]', ' ', uni).strip().lower() - slug_str = re.sub('[-\s]+', '-', slug_str) - - return slug_str[:max_length] + slug_str = re.sub(r'[\W_]', ' ', uni).strip().lower() + slug_str = re.sub(r'[-\s]+', '-', slug_str) + return slug_str[:max_length] if max_length > 0 else slug_str -def slugify(s, max_length=None, path=False): +def slugify(s, max_length=0, path=False): if not path: return slugify_one(s, max_length=max_length) else: