summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2010-07-19 15:59:28 +0200
committerMarcel Hellkamp <marc@gsites.de>2010-07-19 15:59:28 +0200
commit7167854d877b999ad98016f7f81220a3be6c0b2a (patch)
tree146cfeeab758058cbcb98f189f93e9e64efb317c
parent68058ace841eea8de01d22a99622c487f79541b6 (diff)
downloadbottle-7167854d877b999ad98016f7f81220a3be6c0b2a.tar.gz
fix: (Issue #83) Bottle.get_url() does not return correct path when SCRIPT_NAME is set.
-rwxr-xr-xbottle.py4
-rwxr-xr-xtest/test_wsgi.py12
2 files changed, 12 insertions, 4 deletions
diff --git a/bottle.py b/bottle.py
index d87ed74..f4c1c12 100755
--- a/bottle.py
+++ b/bottle.py
@@ -432,7 +432,9 @@ class Bottle(object):
def get_url(self, routename, **kargs):
""" Return a string that matches a named route """
- return '/' + self.routes.build(routename, **kargs)
+ scriptname = request.environ.get('SCRIPT_NAME', '').strip('/') + '/'
+ location = self.routes.build(routename, **kargs).lstrip('/')
+ return urljoin(urljoin('/', scriptname), location)
def route(self, path=None, method='GET', **kargs):
""" Decorator: bind a function to a GET request path.
diff --git a/test/test_wsgi.py b/test/test_wsgi.py
index 9fc91a3..d3ca297 100755
--- a/test/test_wsgi.py
+++ b/test/test_wsgi.py
@@ -182,11 +182,17 @@ class TestDecorators(ServerTestBase):
self.assertBody('', '/test/304')
def test_routebuild(self):
- """ WSGI: Test validate-decorator"""
- @bottle.route('/a/:b/c', name='named')
- def test(var): pass
+ """ WSGI: Test route builder """
+ bottle.route('/a/:b/c', name='named')(5)
+ bottle.request.environ['SCRIPT_NAME'] = ''
self.assertEqual('/a/xxx/c', bottle.url('named', b='xxx'))
self.assertEqual('/a/xxx/c', bottle.app().get_url('named', b='xxx'))
+ bottle.request.environ['SCRIPT_NAME'] = '/app'
+ self.assertEqual('/app/a/xxx/c', bottle.url('named', b='xxx'))
+ bottle.request.environ['SCRIPT_NAME'] = '/app/'
+ self.assertEqual('/app/a/xxx/c', bottle.url('named', b='xxx'))
+ bottle.request.environ['SCRIPT_NAME'] = 'app/'
+ self.assertEqual('/app/a/xxx/c', bottle.url('named', b='xxx'))
def test_decorators(self):
app = bottle.Bottle()