Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request.static_url quotes paths twice #407

Closed
wichert opened this issue Jan 19, 2012 · 0 comments
Closed

request.static_url quotes paths twice #407

wichert opened this issue Jan 19, 2012 · 0 comments

Comments

@wichert
Copy link
Member

wichert commented Jan 19, 2012

When generating a static URL the path is encoded twice. Here is an example:

>>> import pyramid.testing
>>> config = pyramid.testing.setUp()
>>> config.add_static_view('images', path='mypkg:templates')
>>> request=pyramid.testing.DummyRequest()
>>> request.static_url('mypkg:templates/one%2Ftwo')
'http://example.com/images/one%25252Ftwo'

notice how %2F has been transformed into %25252F. This results in a broken URL since for incoming requests the URL is only dequoted once (as it should be).

Looking at pyramid code the first quoting happens inside StaticURLInfo.generate:

if path.startswith(spec):
    subpath = urllib.quote(path[len(spec):])
    if url is None:
        kw['subpath'] = subpath
        return request.route_url(route_name, **kw)
    else:
        return urljoin(url, subpath)

and the again when StaticURLInfo calls route_url, which uses quote_path_segment again:

 # a stararg argument
if hasattr(v, '__iter__'):
    v = '/'.join([quote_path_segment(x) for x in v]) # native

I suspect that the right fix here is to remove the quoting done in StaticURLInfo and rely on route_url to quote paths correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants