Pylons/pyramid — Issue #349: static URLs unqouted twice
Author: wichert
Created: 2011-11-10 10:11:25+00:00
State: open

For a project I need a directory structures for images, where each directory name may have undesirable characters such as /. To solve this I am URL-quoting directory names on the filesystem. That means I have paths such as ```media/help/tops/halter%20tops/one%2Btwo/image 1.jpg``` . I can build a static URL for those in the usual way, for example {{{request.static_url('mypackage:templates/media/help/tops/halter%20tops/image 1.jpg}}}, which results in the URL {{{http://localhost/media/help/tops/halter%20tops/image 1.jpg}}. This URL has a problem when used as-is: the spaces and %-sign still need to be quoted. This is problem one:

1. static_url should probably do URL-quoting

as a workaround I modified my code to double-quote the directory names and quote the filenames. That results in URLs such as {{{http://localhost/media/help/hater%2520tops/image%201.jpg}}}. This still does not work: something in the pyramid is double-unquoting incoming paths, and as a result I still get a 404. This is the second problem:

2. PATH_INFO is URL-unquoted twice for static views, leading to problems with filesystem paths that themselves use URL-quoting

as a last attempt I tried to tripple-quote everything. This produces lovely URLs such as {{{http://localhost/media/help/hater%252520tops/image%25201.jpg}}}, but does end up working.