From 7742887e963f805d461d8a3b0b19b8fb1a628328 Mon Sep 17 00:00:00 2001 From: Bohdan Lisnenko Date: Mon, 3 Jun 2019 13:06:41 +0000 Subject: [PATCH] [FIX] http_routing: slugify_lib - max_length param should be int MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes odoo/odoo#33858 Signed-off-by: Jérémy Kersten (jke) closes odoo/odoo#34363 Signed-off-by: Jérémy Kersten (jke) --- addons/http_routing/models/ir_http.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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: