Skip to content

Commit

Permalink
Prevent double quoting of paths in static urls.
Browse files Browse the repository at this point in the history
  • Loading branch information
wichert committed Jan 19, 2012
1 parent ab32ca0 commit 4248344
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
3 changes: 2 additions & 1 deletion pyramid/config/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1422,11 +1422,12 @@ def generate(self, path, request, **kw):
registry = get_current_registry()
for (url, spec, route_name) in self._get_registrations(registry):
if path.startswith(spec):
subpath = urllib.quote(path[len(spec):])
subpath = path[len(spec):]
if url is None:
kw['subpath'] = subpath
return request.route_url(route_name, **kw)
else:
subpath = urllib.quote(subpath)
return urljoin(url, subpath)

raise ValueError('No static URL definition matching %s' % path)
Expand Down
25 changes: 12 additions & 13 deletions pyramid/tests/test_config/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3333,6 +3333,18 @@ def test_generate_slash_in_name2(self):
result = inst.generate('package:path/', request)
self.assertEqual(result, 'http://example.com/foo/')

def test_generate_quoting(self):
config = testing.setUp()
try:
config.add_static_view('images', path='mypkg:templates')
inst = self._makeOne()
request = testing.DummyRequest()
request.registry = config.registry
result = inst.generate('mypkg:templates/foo%2Fbar', request)
self.assertEqual(result, 'http://example.com/images/foo%252Fbar')
finally:
testing.tearDown()

def test_generate_route_url(self):
inst = self._makeOne()
registrations = [(None, 'package:path/', '__viewname/')]
Expand All @@ -3346,19 +3358,6 @@ def route_url(n, **kw):
result = inst.generate('package:path/abc', request, a=1)
self.assertEqual(result, 'url')

def test_generate_url_quoted_local(self):
inst = self._makeOne()
registrations = [(None, 'package:path/', '__viewname/')]
inst._get_registrations = lambda *x: registrations
def route_url(n, **kw):
self.assertEqual(n, '__viewname/')
self.assertEqual(kw, {'subpath':'abc%20def', 'a':1})
return 'url'
request = self._makeRequest()
request.route_url = route_url
result = inst.generate('package:path/abc def', request, a=1)
self.assertEqual(result, 'url')

def test_generate_url_quoted_remote(self):
inst = self._makeOne()
registrations = [('http://example.com/', 'package:path/', None)]
Expand Down

0 comments on commit 4248344

Please sign in to comment.