[FIX] website: encode lang (come from database) into utf-8 before join

Join can fail if url contains non-ascii char

Fix urls like:
   /page/波
   /page/русский
   /page/%D1%80%D1%83%D1%81%D1%81%D0%BA%D0%B8%D0%B9
This commit is contained in:
Jeremy Kersten
2016-02-11 09:30:04 +01:00
parent 07d7147846
commit e48439d89c
+2 -2
View File
@@ -53,13 +53,13 @@ def url_for(path_or_uri, lang=None):
if ps[1] in langs:
# Replace the language only if we explicitly provide a language to url_for
if force_lang:
ps[1] = lang
ps[1] = lang.encode('utf-8')
# Remove the default language unless it's explicitly provided
elif ps[1] == request.website.default_lang_code:
ps.pop(1)
# Insert the context language or the provided language
elif lang != request.website.default_lang_code or force_lang:
ps.insert(1, lang)
ps.insert(1, lang.encode('utf-8'))
location = '/'.join(ps)
return location.decode('utf-8')