Pylons/pyramid — Issue #407: static URLs are quoted twice when generated
Author: wichert
Created: 2012-01-19 15:37:17+00:00
State: open

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

```
(Pdb) pp request.static_url('s4u.article:aspect-images/coat/jeans%2Fdenim/2f8f045076a16b8f99fdb5cfc36071ec.jpg')
'http://localhost:5000/aspect-images/coat/jeans%25252Fdenim/2f8f045076a16b8f99fdb5cfc36071ec.jpg'
```

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:

```python
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:

```python
# 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.