# HG changeset patch # User RĂ©mi Cardona # Date 1400861864 -7200 # Node ID e3d2012adcd09ad26eb825795ed76ba7029a8e15 # Parent af6e3db801fcfbd6f562c4a7cfdc89f187042792 [request] Ensure base_url() always has a trailing '/' (closes #3955093) Just as an example, cubicweb.ajax.js is clearly written under the assumption that BASE_URL/baseuri() - which simply contains req.base_url() - has a trailing /. diff -r af6e3db801fc -r e3d2012adcd0 req.py --- a/req.py Mon Jun 02 12:23:18 2014 +0200 +++ b/req.py Fri May 23 18:17:44 2014 +0200 @@ -472,12 +472,16 @@ raise ValueError(self._('can\'t parse %(value)r (expected %(format)s)') % {'value': value, 'format': format}) + def _base_url(self, secure=None): + if secure: + return self.vreg.config.get('https-url') or self.vreg.config['base-url'] + return self.vreg.config['base-url'] + def base_url(self, secure=None): """return the root url of the instance """ - if secure: - return self.vreg.config.get('https-url') or self.vreg.config['base-url'] - return self.vreg.config['base-url'] + url = self._base_url(secure=secure) + return url if url is None else url.rstrip('/') + '/' # abstract methods to override according to the web front-end ############# diff -r af6e3db801fc -r e3d2012adcd0 test/unittest_dbapi.py --- a/test/unittest_dbapi.py Mon Jun 02 12:23:18 2014 +0200 +++ b/test/unittest_dbapi.py Fri May 23 18:17:44 2014 +0200 @@ -78,7 +78,7 @@ with tempattr(cnx.vreg, 'config', config): cnx.use_web_compatible_requests('http://perdu.com') req = cnx.request() - self.assertEqual(req.base_url(), 'http://perdu.com') + self.assertEqual(req.base_url(), 'http://perdu.com/') self.assertEqual(req.from_controller(), 'view') self.assertEqual(req.relative_path(), '') req.ajax_replace_url('domid') # don't crash diff -r af6e3db801fc -r e3d2012adcd0 web/request.py --- a/web/request.py Mon Jun 02 12:23:18 2014 +0200 +++ b/web/request.py Fri May 23 18:17:44 2014 +0200 @@ -162,7 +162,7 @@ self.ajax_request = value json_request = property(_get_json_request, _set_json_request) - def base_url(self, secure=None): + def _base_url(self, secure=None): """return the root url of the instance secure = False -> base-url @@ -175,7 +175,7 @@ if secure: base_url = self.vreg.config.get('https-url') if base_url is None: - base_url = super(_CubicWebRequestBase, self).base_url() + base_url = super(_CubicWebRequestBase, self)._base_url() return base_url @property