diff options
| author | Fabien Meghazi <fme@openerp.com> | 2014-03-10 14:05:30 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2014-03-10 14:05:30 +0100 |
| commit | 5e036bbf7c1e79dc1fe91b9be04c329aad7db995 (patch) | |
| tree | 935815e58918c5959b22e493ab77beefbc53f1f7 | |
| parent | 35d87dd19bc47751a3825f595952f9180f6f3cbe (diff) | |
[FIX] Properly redirect in case of invalid url slugs
Use werkzeug's api instead of doing hackish url replacement
bzr revid: fme@openerp.com-20140310130530-e86cdwhdca9cs9g3
| -rw-r--r-- | addons/website/models/ir_http.py | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/addons/website/models/ir_http.py b/addons/website/models/ir_http.py index 46b9efc15a8..f73138313ab 100644 --- a/addons/website/models/ir_http.py +++ b/addons/website/models/ir_http.py @@ -78,21 +78,18 @@ class ir_http(orm.AbstractModel): return self._dispatch() - def _postprocess_args(self, arguments): - url = request.httprequest.url - for arg in arguments.itervalues(): - if isinstance(arg, orm.browse_record) and isinstance(arg._uid, RequestUID): - placeholder = arg._uid - arg._uid = request.uid - try: - good_slug = slug(arg) - if str(arg.id) != placeholder.value and placeholder.value != good_slug: - # TODO: properly recompose the url instead of using replace() - url = url.replace(placeholder.value, good_slug) - except KeyError: - return self._handle_exception(werkzeug.exceptions.NotFound()) - if url != request.httprequest.url: - werkzeug.exceptions.abort(werkzeug.utils.redirect(url)) + def _postprocess_args(self, arguments, rule): + for arg, val in arguments.items(): + # Replace uid placeholder by the current request.uid + if isinstance(val, orm.browse_record) and isinstance(val._uid, RequestUID): + val._uid = request.uid + try: + _, path = rule.build(arguments) + assert path is not None + except Exception: + return self._handle_exception(werkzeug.exceptions.NotFound()) + if path != request.httprequest.path: + return werkzeug.utils.redirect(path) def _handle_exception(self, exception=None, code=500): if isinstance(exception, werkzeug.exceptions.HTTPException) and hasattr(exception, 'response') and exception.response: |
