diff options
author | Marcel Hellkamp <marc@gsites.de> | 2010-07-19 15:59:28 +0200 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2010-07-19 15:59:28 +0200 |
commit | 7167854d877b999ad98016f7f81220a3be6c0b2a (patch) | |
tree | 146cfeeab758058cbcb98f189f93e9e64efb317c | |
parent | 68058ace841eea8de01d22a99622c487f79541b6 (diff) | |
download | bottle-7167854d877b999ad98016f7f81220a3be6c0b2a.tar.gz |
fix: (Issue #83) Bottle.get_url() does not return correct path when SCRIPT_NAME is set.
-rwxr-xr-x | bottle.py | 4 | ||||
-rwxr-xr-x | test/test_wsgi.py | 12 |
2 files changed, 12 insertions, 4 deletions
@@ -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() |