summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/base.py1
-rw-r--r--routes/util.py2
-rw-r--r--tests/test_utils.py16
3 files changed, 19 insertions, 0 deletions
diff --git a/routes/base.py b/routes/base.py
index 7d8834f..814a99e 100644
--- a/routes/base.py
+++ b/routes/base.py
@@ -444,6 +444,7 @@ class Mapper(object):
self._regprefix = None
self._routenames = {}
self.debug = False
+ self.append_slash = False
if register:
config = request_config()
config.mapper = self
diff --git a/routes/util.py b/routes/util.py
index 6f81ec2..2cb80be 100644
--- a/routes/util.py
+++ b/routes/util.py
@@ -115,6 +115,8 @@ def url_for(*args, **kargs):
else:
newargs = _screenargs(kargs)
url = config.mapper.generate(**newargs)
+ if config.mapper.append_slash and not url.endswith('/'):
+ url += '/'
if anchor: url += '#' + _url_quote(anchor)
if host or protocol:
if not host: host = config.host
diff --git a/tests/test_utils.py b/tests/test_utils.py
index c1fcbab..e514015 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -176,6 +176,22 @@ class TestUtils(unittest.TestCase):
self.assertEqual('http://www.google.com/search?q=routes', url_for('http://www.google.com/search', q='routes'))
self.assertEqual('/delicious.jpg', url_for('/delicious.jpg'))
self.assertEqual('/delicious/search?v=routes', url_for('/delicious/search', v='routes'))
+
+ def test_append_slash(self):
+ m = self.con.mapper
+ self.con.mapper_dict = {}
+ m.append_slash = True
+ self.con.environ = dict(SCRIPT_NAME='', SERVER_NAME='example.com')
+ m.connect(':controller/:action/:id')
+ m.connect('home', 'http://www.groovie.org/', _static=True)
+ m.connect('space', '/nasa/images', _static=True)
+ m.create_regs(['content', 'blog'])
+
+ self.assertEqual('http://www.google.com/search', url_for('http://www.google.com/search'))
+ self.assertEqual('http://www.google.com/search?q=routes', url_for('http://www.google.com/search', q='routes'))
+ self.assertEqual('/delicious.jpg', url_for('/delicious.jpg'))
+ self.assertEqual('/delicious/search?v=routes', url_for('/delicious/search', v='routes'))
+ self.assertEqual('/content/list/', url_for(controller='/content', action='list'))
def test_no_named_path_with_script(self):
m = self.con.mapper