Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.0][IMP][website_canonical_url] Safer, prefer root, relative paths #260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website_canonical_url/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Contributors

* Thomas Rehn <[email protected]>
* Rami Alwafaie <[email protected]>
* Jairo Llopis <[email protected]>

Maintainer
----------
Expand Down
8 changes: 3 additions & 5 deletions website_canonical_url/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

{
'name': "Website Canoncial URL",
'summary': """
Canonical URL in Website Headers
""",
'author': "initOS GmbH, Odoo Community Association (OCA)",
'summary': "Canonical URL in Website Headers",
'author': "initOS GmbH, Tecnativa, Odoo Community Association (OCA)",
'website': "http://www.initos.com",
'category': 'Website',
'version': '8.0.1.0.0',
'version': '8.0.1.1.0',
'license': 'AGPL-3',
'depends': [
'website',
Expand Down
15 changes: 11 additions & 4 deletions website_canonical_url/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ def get_canonical_url(self, req=None):
canonical_url = None
if req is None:
req = request
if req and req.httprequest.base_url:
lang = self._context['lang']
if req and req.httprequest.path:
lang = self.env.lang
if lang == request.website.default_lang_code:
canonical_url = req.httprequest.base_url
canonical_url = req.httprequest.path
else:
url_parts = urlparse(req.httprequest.base_url)
url_parts = urlparse(req.httprequest.path)
url_parts = list(url_parts)
# change the path of the url
url_parts[2] = lang + url_parts[2]
canonical_url = urlunparse(url_parts)
# Special case for rerouted requests to root path
try:
if (canonical_url.startswith("/page/") and
self.menu_id.child_id[0].url == canonical_url):
canonical_url = "/"
except:
pass
return canonical_url