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

static URLs unqouted twice #349

Closed
wichert opened this issue Nov 10, 2011 · 2 comments

Comments

Projects
None yet
2 participants
@wichert
Copy link
Member

commented Nov 10, 2011

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:

  1. 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.

@mcdonc

This comment has been minimized.

Copy link
Member

commented Nov 18, 2011

Problem 2 appears to be fixed in the trunk.

  • Render a new starter scaffold.
  • Add a directory named "halter%20tops" to the "static" directory of the package.
  • Add a jpeg image within the "halter%20tops" directory named "image 1.jpg"
  • Start the server; visit "http://localhost:6543/static/halter%2520tops/image%201.jpg".. the image will be rendered.
@mcdonc

This comment has been minimized.

Copy link
Member

commented Nov 18, 2011

Problem 1 (static_url) I've fixed on master.

Going to look into fixing this on the 1.2 branch too.

@mcdonc mcdonc closed this in 7fe36a3 Nov 18, 2011

mcdonc added a commit that referenced this issue Nov 18, 2011

- Backport fix from master: ``request.static_url`` now generates URL-…
…quoted

  URLs when fed a ``path`` argument which contains characters that are
  unsuitable for URLs.  See #349 for
  more information.

- Backport from master: fix ``request.json_body`` to deal with alternate
  request charsets.

Ref: issue #349.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.