From dcac4cc0dfd4412e1139399fb17ec7ba6118aad4 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 1 Aug 2014 10:50:25 +0200 Subject: [PATCH] [FIX] website: slug: fallback to positive ID when slug appears to contain a missing negative ID In some rare cases database records have negative IDs, so the slug URL could look like /foo--20. This could be mistaken for a slug ending with a `-` and a positive ID. The latter is not supposed to happned as final hyphens are stripped by slugify, but has been used in the past and may be used in old links. --- addons/website/models/ir_http.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 8c09c998bd1..76386f03b90 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -241,8 +241,13 @@ class ModelConverter(ir.ir_http.ModelConverter): def to_python(self, value): m = re.match(self.regex, value) _uid = RequestUID(value=value, match=m, converter=self) + record_id = int(m.group(2)) + if record_id < 0: + # limited support for negative IDs due to our slug pattern, assume abs() if not found + if not request.registry[self.model].exists(request.cr, _uid, [record_id]): + record_id = abs(record_id) return request.registry[self.model].browse( - request.cr, _uid, int(m.group(2)), context=request.context) + request.cr, _uid, record_id, context=request.context) def generate(self, cr, uid, query=None, args=None, context=None): obj = request.registry[self.model]