diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2019-03-25 10:48:10 +0000 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2019-03-25 10:53:25 +0000 |
| commit | 2a89f0c7f8a9d8f95036cd5062b15efc702e5e51 (patch) | |
| tree | 1af18b6077ce030c93a091f1f2c2f86ad482282d | |
| parent | d3bd48d67baeda427c869c53cea1a1715670120c (diff) | |
[REV] "[FIX] website: language prefixed URL on website"
This reverts commit 5324284f560dd15ef949dab3b00d238a3bfa2b5e
This reverts commit ad826f56ba49caba0881a40609083cf73250d610.
If for example we had in a template:
<script type="text/javascript" src="/payment_stripe/static/src/js/stripe.js"></script>
it has been reproduced to be gotten as:
<script type="text/javascript" src="/de_DE/payment_stripe/static/src/js/stripe.js"></script>
which is unexpected and could cause an error.
closes #32090
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
| -rw-r--r-- | addons/http_routing/models/ir_http.py | 2 | ||||
| -rw-r--r-- | addons/website/models/ir_qweb.py | 9 | ||||
| -rw-r--r-- | addons/website/tests/test_qweb.py | 94 |
3 files changed, 2 insertions, 103 deletions
diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index c7232768d82..0129bc90e6d 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -164,7 +164,7 @@ def is_multilang_url(local_url, langs=None): local_url = '/'.join(spath) try: # Try to match an endpoint in werkzeug's routing table - url = local_url.partition('#')[0].split('?') + url = local_url.split('?') path = url[0] query_string = url[1] if len(url) > 1 else None router = request.httprequest.app.get_db_router(request.db).bind('') diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py index 3c082964ddc..0f73bc469f5 100644 --- a/addons/website/models/ir_qweb.py +++ b/addons/website/models/ir_qweb.py @@ -6,7 +6,6 @@ from collections import OrderedDict from odoo import models from odoo.http import request -from odoo.addons.http_routing.models.ir_http import url_for re_background_image = re.compile(r"(background-image\s*:\s*url\(\s*['\"]?\s*)([^)'\"]+)") @@ -38,16 +37,10 @@ class QWeb(models.AbstractModel): if not website and options.get('website_id'): website = self.env['website'].browse(options['website_id']) - if not website: + if not website or not website.cdn_activated: return atts name = self.URL_ATTRS.get(tagName) - if request and name and name in atts: - atts[name] = url_for(atts[name]) - - if not website.cdn_activated: - return atts - if name and name in atts: atts = OrderedDict(atts) atts[name] = website.get_cdn_url(atts[name]) diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py index 3e697d6842d..e73083a66b2 100644 --- a/addons/website/tests/test_qweb.py +++ b/addons/website/tests/test_qweb.py @@ -3,7 +3,6 @@ import re -import odoo from odoo import tools from odoo.modules.module import get_module_resource from odoo.tests.common import TransactionCase @@ -64,96 +63,3 @@ class TestQweb(TransactionCase): "css": attachments[1].url, "user_id": demo.id, }).encode('utf8')) - -class MockObject(object): - def __init__(self, *args, **kwargs): - self.__dict__ = kwargs - def __call__(self, *args, **kwargs): - return self - def __getitem__(self, index): - return self - -class MockRequest(object): - """ Class with context manager mocking odoo.http.request for tests """ - def __init__(self, env, website=None, context=None, multilang=True): - app = MockObject(routing={ - 'type': 'http', - 'website': True, - 'multilang': multilang, - }) - app.get_db_router = app.bind = app.match = app - self.request = MockObject( - env=env, context=context or {}, db=None, debug=False, - website=website, httprequest=MockObject( - path='/hello/', - app=app - ) - ) - odoo.http._request_stack.push(self.request) - def __enter__(self): - return self.request - def __exit__(self, exc_type, exc_value, traceback): - odoo.http._request_stack.pop() - -class TestQwebProcessAtt(TransactionCase): - def setUp(self): - super(TestQwebProcessAtt, self).setUp() - self.website = self.env['website'].browse(1) - self.website.language_ids = self.env.ref('base.lang_en') + self.env.ref('base.lang_fr') - self.website.default_lang_id = self.env.ref('base.lang_en') - self.website.cdn_activated = True - self.website.cdn_url = "http://test.cdn" - self.website.cdn_filters = "\n".join(["^(/[a-z]{2}_[A-Z]{2})?/a$", "^/b$"]) - - def _test_att(self, url, expect, tag='a', attribute='href'): - self.assertEqual( - self.env['ir.qweb']._post_processing_att(tag, {attribute: url}, {}), - expect - ) - - def test_process_att_no_request(self): - # no request so no URL rewriting - self._test_att('/', {'href': '/'}) - self._test_att('/en_US/', {'href': '/en_US/'}) - self._test_att('/fr_FR/', {'href': '/fr_FR/'}) - # no URL rewritting for CDN - self._test_att('/a', {'href': '/a'}) - - def test_process_att_no_website(self): - with MockRequest(self.env) as request: - # no website so URL rewriting - self._test_att('/', {'href': '/'}) - self._test_att('/en_US/', {'href': '/en_US/'}) - self._test_att('/fr_FR/', {'href': '/fr_FR/'}) - # no URL rewritting for CDN - self._test_att('/a', {'href': '/a'}) - - def test_process_att_monolang_route(self): - with MockRequest(self.env, website=self.website, multilang=False) as request: - # lang not changed in URL but CDN enabled - self._test_att('/a', {'href': 'http://test.cdn/a'}) - self._test_att('/en_US/a', {'href': 'http://test.cdn/en_US/a'}) - self._test_att('/b', {'href': 'http://test.cdn/b'}) - self._test_att('/en_US/b', {'href': '/en_US/b'}) - - def test_process_att_no_request_lang(self): - with MockRequest(self.env, self.website) as request: - self._test_att('/', {'href': '/'}) - self._test_att('/en_US/', {'href': '/'}) - self._test_att('/fr_FR/', {'href': '/fr_FR/'}) - - def test_process_att_with_request_lang(self): - with MockRequest(self.env, self.website, context={'lang': 'fr_FR'}) as request: - self._test_att('/', {'href': '/fr_FR/'}) - self._test_att('/en_US/', {'href': '/'}) - self._test_att('/fr_FR/', {'href': '/fr_FR/'}) - - def test_process_att_matching_cdn_and_lang(self): - with MockRequest(self.env, self.website) as request: - # lang prefix is added before CDN - self._test_att('/a', {'href': 'http://test.cdn/a'}) - self._test_att('/en_US/a', {'href': 'http://test.cdn/a'}) - self._test_att('/fr_FR/a', {'href': 'http://test.cdn/fr_FR/a'}) - self._test_att('/b', {'href': 'http://test.cdn/b'}) - self._test_att('/en_US/b', {'href': 'http://test.cdn/b'}) - self._test_att('/fr_FR/b', {'href': '/fr_FR/b'}) |
