From 05f462e9792d9b5f6560968503795dc162984408 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 19 Jan 2012 20:36:45 -0500 Subject: Backport fix for issue #407 to 1.3 branch. --- CHANGES.txt | 3 +++ pyramid/config/views.py | 3 ++- pyramid/tests/test_config/test_views.py | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index bfafaaae3..c1b6ae976 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) ================== diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 8d7885bd2..0359c46f7 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -1545,11 +1545,12 @@ class StaticURLInfo(object): 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) diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index aa941c0cf..4af29325a 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -3542,6 +3542,18 @@ class TestStaticURLInfo(unittest.TestCase): 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 @@ class TestStaticURLInfo(unittest.TestCase): 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 -- cgit v1.2.3