diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index 444a8e5241f..8a8513392d8 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -421,6 +421,13 @@ class IrHttp(models.AbstractModel): and getattr(request, 'is_frontend_multilang', True) ) + # Some URLs in website are concatenated, first url ends with /, + # second url starts with /, resulting url contains two following + # slashes that must be merged. + if allow_redirect and '//' in path: + new_url = path.replace('//', '/') + werkzeug.exceptions.abort(request.redirect(new_url, code=301, local=True)) + # There is no user on the environment yet but the following code # requires one to set the lang on the request. Temporary grant # the public user. Don't try it at home! diff --git a/addons/website/tests/test_http_endpoint.py b/addons/website/tests/test_http_endpoint.py index c81d6cf8934..b275a014377 100644 --- a/addons/website/tests/test_http_endpoint.py +++ b/addons/website/tests/test_http_endpoint.py @@ -2,6 +2,8 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.tests import HttpCase +import werkzeug + class TestHttpEndPoint(HttpCase): @@ -30,3 +32,8 @@ class TestHttpEndPoint(HttpCase): r = self.url_open('/') r.raise_for_status() + + def test_redirect_double_slash(self): + res = self.url_open('/test_http//greeting', allow_redirects=False) + self.assertEqual(res.status_code, 301) + self.assertEqual(werkzeug.urls.url_parse(res.headers.get('Location', '')).path, '/test_http/greeting') diff --git a/odoo/addons/test_http/tests/test_misc.py b/odoo/addons/test_http/tests/test_misc.py index 5aebb826613..d316c049784 100644 --- a/odoo/addons/test_http/tests/test_misc.py +++ b/odoo/addons/test_http/tests/test_misc.py @@ -19,8 +19,7 @@ from .test_common import TestHttpBase class TestHttpMisc(TestHttpBase): def test_misc0_redirect(self): res = self.nodb_url_open('/test_http//greeting') - self.assertEqual(res.status_code, 301) - self.assertEqual(urlparse(res.headers.get('Location', '')).path, '/test_http/greeting') + self.assertEqual(res.status_code, 404) def test_misc1_reverse_proxy(self): # client <-> reverse-proxy <-> odoo diff --git a/odoo/http.py b/odoo/http.py index ea093266d46..1d1fa290b94 100644 --- a/odoo/http.py +++ b/odoo/http.py @@ -1968,14 +1968,6 @@ class Application: return ProxyFix(fake_app)(environ, fake_start_response) - # Some URLs in website are concatenated, first url ends with /, - # second url starts with /, resulting url contains two following - # slashes that must be merged. - if environ['REQUEST_METHOD'] == 'GET' and '//' in environ['PATH_INFO']: - response = werkzeug.utils.redirect( - environ['PATH_INFO'].replace('//', '/'), 301) - return response(environ, start_response) - httprequest = werkzeug.wrappers.Request(environ) httprequest.user_agent_class = UserAgent # use vendored userAgent since it will be removed in 2.1 httprequest.parameter_storage_class = (