summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2010-02-28 15:33:42 -0800
committerBen Bangert <ben@groovie.org>2010-02-28 15:33:42 -0800
commit93adcc44b9de85012f3c79360c949f5a8fa69c1d (patch)
treeae618ed87ea4f4e395632352c4ec7d7ac73f944b
parentacc95ed092e9efe366f89ef92f6d7d975e3aa12a (diff)
downloadroutes-93adcc44b9de85012f3c79360c949f5a8fa69c1d.tar.gz
* Fix bug with relative URL's using qualified merging host and URL without
including the appropriate slash. Fixes #13. --HG-- branch : trunk
-rw-r--r--CHANGELOG2
-rw-r--r--routes/util.py4
-rw-r--r--tests/test_functional/test_generation.py11
3 files changed, 16 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index b83af72..154bbdd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,8 @@ Routes Changelog
Release 1.12 (**tip**)
======================
+* Fix bug with relative URL's using qualified merging host and URL without
+ including the appropriate slash. Fixes #13.
* Fix bug with mapper.extend and Routes modifying their original args.
Fixes #24.
* Fix url.current() not returning current args when explicit is True.
diff --git a/routes/util.py b/routes/util.py
index 71bdf1d..b2dac6d 100644
--- a/routes/util.py
+++ b/routes/util.py
@@ -399,7 +399,9 @@ class URLGenerator(object):
if not protocol:
protocol = hostinfo['protocol']
if url is not None:
- url = protocol + '://' + host + url
+ if host[-1] != '/':
+ host += '/'
+ url = protocol + '://' + host + url.lstrip('/')
if not isinstance(url, str) and url is not None:
raise GenerationException("Can only return a string, got "
diff --git a/tests/test_functional/test_generation.py b/tests/test_functional/test_generation.py
index 68b6cba..1e379c7 100644
--- a/tests/test_functional/test_generation.py
+++ b/tests/test_functional/test_generation.py
@@ -22,6 +22,17 @@ class TestGeneration(unittest.TestCase):
eq_('/hi/show', m.generate(fred='show'))
eq_('/hi/list%20people', m.generate(fred='list people'))
eq_(None, m.generate())
+
+ def test_relative_url(self):
+ m = Mapper(explicit=False)
+ m.minimization = True
+ m.environ = dict(HTTP_HOST='localhost')
+ url = URLGenerator(m, m.environ)
+ m.connect(':controller/:action/:id')
+ m.create_regs(['content','blog','admin/comments'])
+
+ eq_('about', url('about'))
+ eq_('http://localhost/about', url('about', qualified=True))
def test_basic_dynamic_explicit_use(self):
m = Mapper()