diff options
author | Ben Bangert <ben@groovie.org> | 2015-01-17 13:35:41 -0800 |
---|---|---|
committer | Ben Bangert <ben@groovie.org> | 2015-01-17 13:35:41 -0800 |
commit | dcdb3f39a072dbb8fcc7bf8365be05af5ca4b4e1 (patch) | |
tree | beb4f35dc887bfa9ae09a593c0ea1d19870c1e10 | |
parent | c896e82611f9f4ae7962de7dfa4734d7c4342be6 (diff) | |
download | routes-dcdb3f39a072dbb8fcc7bf8365be05af5ca4b4e1.tar.gz |
* Fix regression that didn't allow passing in params 'host', 'protocol', or
'anchor'. They can now be passed in with a trailing '_' as was possible
before commit d1d1742903fa5ca24ef848a6ae895303f2661b2a. Fixes #7.
-rw-r--r-- | CHANGELOG.rst | 3 | ||||
-rw-r--r-- | routes/util.py | 4 | ||||
-rw-r--r-- | tests/test_functional/test_explicit_use.py | 14 |
3 files changed, 19 insertions, 2 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e883078..3f79c37 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,6 +3,9 @@ Routes Changelog Release 2.1 (**dev**) ===================== +* Fix regression that didn't allow passing in params 'host', 'protocol', or + 'anchor'. They can now be passed in with a trailing '_' as was possible + before commit d1d1742903fa5ca24ef848a6ae895303f2661b2a. Fixes #7. * URL generation with/without SCRIPT_NAME was resulting in the URL cache failing to return the appropriate cached URL generation. The URL cache should always include the SCRIPT_NAME, even if its empty, in the cache diff --git a/routes/util.py b/routes/util.py index 5b3fae1..9834ad5 100644 --- a/routes/util.py +++ b/routes/util.py @@ -184,6 +184,8 @@ def url_for(*args, **kargs): for key in ['anchor', 'host', 'protocol']: if kargs.get(key): del kargs[key] + if key+'_' in kargs: + kargs[key] = kargs.pop(key+'_') config = request_config() route = None static = False @@ -326,6 +328,8 @@ class URLGenerator(object): for key in ['anchor', 'host', 'protocol']: if kargs.get(key): del kargs[key] + if key+'_' in kargs: + kargs[key] = kargs.pop(key+'_') route = None use_current = '_use_current' in kargs and kargs.pop('_use_current') diff --git a/tests/test_functional/test_explicit_use.py b/tests/test_functional/test_explicit_use.py index d6e1879..32579d8 100644 --- a/tests/test_functional/test_explicit_use.py +++ b/tests/test_functional/test_explicit_use.py @@ -94,7 +94,8 @@ class TestUtils(unittest.TestCase): eq_(map.match('/foo'), {}) def test_using_func(self): - def fred(view): pass + def fred(view): + pass m = Mapper() m.explicit = True @@ -111,7 +112,8 @@ class TestUtils(unittest.TestCase): m.explicit = True m.connect('/{first}/{last}') - environ = {'HTTP_HOST': 'localhost.com', 'PATH_INFO': '/content/index', 'SCRIPT_NAME': '/jones'} + environ = {'HTTP_HOST': 'localhost.com', 'PATH_INFO': '/content/index', + 'SCRIPT_NAME': '/jones'} match = m.routematch(environ=environ)[0] environ['wsgiorg.routing_args'] = (None, match) url = URLGenerator(m, environ) @@ -119,3 +121,11 @@ class TestUtils(unittest.TestCase): eq_('/jones/content/index', url.current()) eq_('/jones/smith/barney', url(first='smith', last='barney')) + def test_with_host_param(self): + m = Mapper() + m.explicit = True + m.connect('/hi/{fred}') + + environ = {'HTTP_HOST': 'localhost.com'} + url = URLGenerator(m, environ) + eq_('/hi/smith?host=here', url(fred='smith', host_='here')) |