Skip to content

Commit

Permalink
Merge pull request #3749 from Zharktas/3499_skip_url_parsing_in_redirect
Browse files Browse the repository at this point in the history
3499 skip url parsing in redirect
  • Loading branch information
wardi committed Aug 29, 2017
2 parents 59359b7 + 18c08da commit f13aef2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
8 changes: 3 additions & 5 deletions ckan/controllers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ def login(self, error=None):
if not c.user:
came_from = request.params.get('came_from')
if not came_from:
came_from = h.url_for(controller='user', action='logged_in',
__ckan_no_root=True)
came_from = h.url_for(controller='user', action='logged_in')
c.login_handler = h.url_for(
self._get_repoze_handler('login_handler_path'),
came_from=came_from)
Expand Down Expand Up @@ -436,10 +435,9 @@ def logout(self):
# Do any plugin logout stuff
for item in p.PluginImplementations(p.IAuthenticator):
item.logout()
url = h.url_for(controller='user', action='logged_out_page',
__ckan_no_root=True)
url = h.url_for(controller='user', action='logged_out_page')
h.redirect_to(self._get_repoze_handler('logout_handler_path') +
'?came_from=' + url)
'?came_from=' + url, parse_url=True)

def logged_out(self):
# redirect if needed
Expand Down
20 changes: 19 additions & 1 deletion ckan/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,32 @@ def redirect_to(*args, **kw):
toolkit.redirect_to('dataset_read', id='changed')
If given a single string as argument, this redirects without url parsing
toolkit.redirect_to('http://example.com')
toolkit.redirect_to('/dataset')
toolkit.redirect_to('/some/other/path')
'''
if are_there_flash_messages():
kw['__no_cache__'] = True

# 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)

_url = ''
skip_url_parsing = False
parse_url = kw.pop('parse_url', False)
if uargs and len(uargs) is 1 and isinstance(uargs[0], basestring) \
and (uargs[0].startswith('/') or is_url(uargs[0])) \
and parse_url is False:
skip_url_parsing = True
_url = uargs[0]

if skip_url_parsing is False:
_url = url_for(*uargs, **kw)

if _url.startswith('/'):
_url = str(config['ckan.site_url'].rstrip('/') + _url)

Expand Down

0 comments on commit f13aef2

Please sign in to comment.