Skip to content
This repository

static URLs unqouted twice #349

Closed
wichert opened this Issue November 10, 2011 · 2 comments

2 participants

Wichert Akkerman Chris McDonough
Wichert Akkerman

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.

Chris McDonough
Owner

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.

Chris McDonough
Owner

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

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

Chris McDonough mcdonc closed this issue from a commit November 18, 2011
Chris McDonough - Backport fixes from master regarding URL decoding. URL segments are
  no-longer "double-decoded" during traversal and when encountered in a route
  subpath (or other star-arg pattern).  As a result, a new API named
  ``pyramid.traversal.traversal_path_info`` was added to the system.  This
  function accepts an already-URL-decoded string and returns a tuple of
  Unicode objects.  This API is used internally by Pyramid in all places that
  ``pyramid.traversal.traversal_path`` used to be used.  The
  ``traversal_path`` function remains for backwards compatibility, however,
  and can still be used when a path is encoded.  See
  #349 for more information.

Closes #349.
7fe36a3
Chris McDonough mcdonc closed this in 7fe36a3 November 18, 2011
Chris McDonough mcdonc referenced this issue from a commit November 18, 2011
Chris McDonough - 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.
28f21cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.