Skip to content

Commit

Permalink
[#3194] Ensure that relative redirects use the host on ckan.site_url
Browse files Browse the repository at this point in the history
Conflicts:
	ckan/lib/helpers.py
  • Loading branch information
amercader committed Aug 22, 2016
1 parent ffa526c commit ed74749
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -142,7 +142,15 @@ def redirect_to(*args, **kw):
'''
if are_there_flash_messages():
kw['__no_cache__'] = True
return _redirect_to(url_for(*args, **kw))

# Routes router doesn't like unicode args
uargs = map(lambda arg: str(arg) if isinstance(arg, unicode) else arg,
args)
_url = url_for(*uargs, **kw)
if _url.startswith('/'):
_url = str(config['ckan.site_url'].rstrip('/') + _url)

return _redirect_to(_url)


@maintain.deprecated('h.url is deprecated please use h.url_for')
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/controllers/test_tags.py
Expand Up @@ -124,7 +124,7 @@ def test_tag_read_redirects_to_dataset_search(self):
tag_url = url_for(controller='tag', action='read', id='find-me')
tag_response = app.get(tag_url, status=302)
assert_equal(tag_response.headers['Location'],
'http://localhost/dataset?tags=find-me')
'http://test.ckan.net/dataset?tags=find-me')

def test_tag_read_not_found(self):
'''Attempting access to non-existing tag returns a 404'''
Expand Down
2 changes: 1 addition & 1 deletion ckan/tests/controllers/test_util.py
Expand Up @@ -18,7 +18,7 @@ def test_redirect_ok(self):
status=302,
)
assert_equal(response.headers.get('Location'),
'http://localhost/dataset')
'http://test.ckan.net/dataset')

def test_redirect_external(self):
app = self._get_test_app()
Expand Down

0 comments on commit ed74749

Please sign in to comment.