From c667eb06b8de63e2567a18521dff125516a88d32 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 5 May 2015 10:12:20 +0200 Subject: [PATCH] [FIX] website: only consider valid languages in URL path Improves aea358ca67f88fa3fb13ac2766c5195223551d10 and avoid spurious redirects for URLs that do not match a controller but do not have a valid language. When the URL does not match any controller, the language matcher tried to strip the leading path component, treating it as a language code. For example: /fr_BE/page/homepage would not match any route, so it would be rerouted internally as /page/homepage, after setting `request.lang` to fr_BE. This breaks the magical 404 handler that allows ir.attachment entries to be mapped to static URLs. Due to the internal rerouting, the mapping of e.g. /website_mycompany/static/src/image/logo.png would be rerouted to /static/src/image/logo.png and not match the mapped URL anymore. Now the stripping of the path component will only occur if that path component matches an installed language code. The consequence is that URLs containing uninstalled language codes will now lead to 404 errors - an acceptable trade-off (e.g. when an older version of the website is still indexed by a search engine) --- addons/website/models/ir_http.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index b3b344415f6..b0bae854949 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -114,8 +114,8 @@ class ir_http(orm.AbstractModel): langs = [lg[0] for lg in request.website.get_languages()] path = request.httprequest.path.split('/') if first_pass: - url_lang = not func and path[1] - nearest_lang = url_lang and self.get_nearest_lang(path[1]) + nearest_lang = not func and self.get_nearest_lang(path[1]) + url_lang = nearest_lang and path[1] preferred_lang = ((cook_lang if cook_lang in langs else False) or self.get_nearest_lang(request.lang) or request.website.default_lang_code)