[FIX] website: wrong canonical URL after reroute
A reroute in an internal redirection, the URL on the current request is changed. The actual changes occurs on the "WSGI environment", a dictionnary that is populated with the request information by the WSGI server (werkzeug in our case). Among all the properties there are PATH_INFO, RAW_URI and REQUEST_URI. * PATH_INFO is the standard value, it contains a RFC-3986 path. `request.httprequest.path` is based on that value. * RAW_URI and REQUEST_PATH are two custom values set by werkzeug to mimic other popular wsgi servers (gunicorn, uwsgi, mod_wsgi), they also only contain a RFC-3986 path. When rerouting only PATH_INFO and RAW_URI are updated. REQUEST_URI is left as-is in order to keep the original path somewhere. When building the cannonical path, one must use the original path instead of the rerouted one. X-original-commit: 779486c4dff23b946b4b14e3dca164ecca4f85a8 Part-of: odoo/odoo#91034
This commit is contained in:
@@ -1312,12 +1312,13 @@ class Website(models.Model):
|
||||
|
||||
router = http.root.get_db_router(request.db).bind('')
|
||||
path = router.build(rule.endpoint, args)
|
||||
if lang != self.default_lang_id:
|
||||
path = f'/{lang.url_code}{path}'
|
||||
except (NotFound, AccessError, MissingError):
|
||||
# The build method returns a quoted URL so convert in this case for consistency.
|
||||
path = urls.url_quote_plus(request.httprequest.path, safe='/')
|
||||
lang_path = f'/{lang.url_code}' if lang != self.default_lang_id else ''
|
||||
path = urls.url_quote_plus(request.httprequest.environ['REQUEST_URI'], safe='/')
|
||||
canonical_query_string = f'?{urls.url_encode(canonical_params)}' if canonical_params else ''
|
||||
return self.get_base_url() + lang_path + path + canonical_query_string
|
||||
return self.get_base_url() + path + canonical_query_string
|
||||
|
||||
def _get_canonical_url(self, canonical_params):
|
||||
"""Returns the canonical URL for the current request."""
|
||||
|
||||
Reference in New Issue
Block a user