Skip to content

Commit

Permalink
[#4872] Remove _external query param on Pylons generated URLs
Browse files Browse the repository at this point in the history
Fixes #4872

The url_for wrapper for Pylons requests correctly handles Flask's
`_external` parameter to generate fully qualified URLs, but fails
to remove it, resulting in an extraneous param added to the URL,
 eg: http://example.com/dataset/test?_external=True
  • Loading branch information
amercader committed Jul 1, 2019
1 parent 13c4e26 commit 4568708
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -398,7 +398,9 @@ def _url_for_pylons(*args, **kw):

# We need to provide protocol and host to get full URLs, get them from
# ckan.site_url
if kw.get('qualified', False) or kw.get('_external', False):
if kw.pop('_external', None):
kw['qualified'] = True
if kw.get('qualified'):
kw['protocol'], kw['host'] = get_site_protocol_and_host()

# The Pylons API routes require a slask on the version number for some
Expand Down
17 changes: 17 additions & 0 deletions ckan/tests/lib/test_helpers.py
Expand Up @@ -321,6 +321,23 @@ def test_url_for_pylons_request_using_flask_url_for(self):

p.unload('test_routing_plugin')

@helpers.change_config('ckan.site_url', 'http://example.com')
def test_url_for_pylons_request_external(self):

if not p.plugin_loaded('test_routing_plugin'):
p.load('test_routing_plugin')


url = 'http://example.com/from_pylons_extension_before_map'
generated_url = h.url_for(
controller='ckan.tests.config.test_middleware:MockPylonsController',
action='view',
_external=True,
)
eq_(generated_url, url)

p.unload('test_routing_plugin')


class TestHelpersRenderMarkdown(object):

Expand Down

0 comments on commit 4568708

Please sign in to comment.