Skip to content
Permalink
Browse files

Backport fix for issue #407 to 1.3 branch.

  • Loading branch information...
mcdonc committed Jan 20, 2012
1 parent 134388a commit 05f462e9792d9b5f6560968503795dc162984408
Showing with 19 additions and 3 deletions.
  1. +3 −0 CHANGES.txt
  2. +2 −1 pyramid/config/views.py
  3. +14 −2 pyramid/tests/test_config/test_views.py
@@ -26,6 +26,9 @@ Bug Fixes
decorator, the view defaults would not be applied. See
https://github.com/Pylons/pyramid/issues/396 .

- Static URL paths were URL-quoted twice. See
https://github.com/Pylons/pyramid/issues/407 .

1.3a5 (2012-01-09)
==================

@@ -1545,11 +1545,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 = url_quote(path[len(spec):])
subpath = path[len(spec):]
if url is None:
kw['subpath'] = subpath
return request.route_url(route_name, **kw)
else:
subpath = url_quote(subpath)
return urljoin(url, subpath)

raise ValueError('No static URL definition matching %s' % path)
@@ -3542,6 +3542,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/')]
@@ -3555,13 +3567,13 @@ 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):
def test_generate_url_unquoted_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})
self.assertEqual(kw, {'subpath':'abc def', 'a':1})
return 'url'
request = self._makeRequest()
request.route_url = route_url

0 comments on commit 05f462e

Please sign in to comment.
You can’t perform that action at this time.