[FIX] website: only consider valid languages in URL path

Improves aea358ca67 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)
This commit is contained in:
Olivier Dony 2015-05-05 10:12:20 +02:00
parent ce32867a90
commit c667eb06b8
1 changed files with 2 additions and 2 deletions

View File

@ -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)