[IMP] http_routing: support redirect of double slash in middle of path

Move code to support only the redirect from url containing double '/' in
the middle of the path.
Keep same behavior than v15 and default Apache behavior.

domain.com//shop/product/1 -> 404
domain.com/shop//product/1 -> 301 -> /shop/product/1

opw-3063387

closes odoo/odoo#106137

X-original-commit: fdd6bf9942e2807b6d1460dba1ca5f61404c7b06
Signed-off-by: Julien Castiaux <juc@odoo.com>
Signed-off-by: Jérémy Kersten <jke@odoo.com>
This commit is contained in:
Jeremy Kersten
2022-11-21 11:50:26 +01:00
parent 77911affbe
commit 2c4556efd1
4 changed files with 15 additions and 10 deletions
+7
View File
@@ -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!
@@ -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')
+1 -2
View File
@@ -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
-8
View File
@@ -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 = (