Browse Source

Merge pull request #2748 from pallets/fix-bp-route

Fix blueprint route for ""
pull/2752/head
David Lord 6 years ago committed by GitHub
parent
commit
a6a6810d56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      flask/blueprints.py
  2. 6
      tests/test_blueprints.py

9
flask/blueprints.py

@ -10,6 +10,7 @@
:license: BSD, see LICENSE for more details. :license: BSD, see LICENSE for more details.
""" """
from functools import update_wrapper from functools import update_wrapper
from werkzeug.urls import url_join
from .helpers import _PackageBoundObject, _endpoint_from_view_func from .helpers import _PackageBoundObject, _endpoint_from_view_func
@ -49,8 +50,6 @@ class BlueprintSetupState(object):
url_prefix = self.options.get('url_prefix') url_prefix = self.options.get('url_prefix')
if url_prefix is None: if url_prefix is None:
url_prefix = self.blueprint.url_prefix url_prefix = self.blueprint.url_prefix
if url_prefix:
url_prefix = url_prefix.rstrip('/')
#: The prefix that should be used for all URLs defined on the #: The prefix that should be used for all URLs defined on the
#: blueprint. #: blueprint.
self.url_prefix = url_prefix self.url_prefix = url_prefix
@ -66,7 +65,11 @@ class BlueprintSetupState(object):
blueprint's name. blueprint's name.
""" """
if self.url_prefix is not None: if self.url_prefix is not None:
rule = '/'.join((self.url_prefix, rule.lstrip('/'))) if rule:
rule = '/'.join((
self.url_prefix.rstrip('/'), rule.lstrip('/')))
else:
rule = self.url_prefix
options.setdefault('subdomain', self.subdomain) options.setdefault('subdomain', self.subdomain)
if endpoint is None: if endpoint is None:
endpoint = _endpoint_from_view_func(view_func) endpoint = _endpoint_from_view_func(view_func)

6
tests/test_blueprints.py

@ -116,6 +116,12 @@ def test_blueprint_app_error_handling(app, client):
@pytest.mark.parametrize(('prefix', 'rule', 'url'), ( @pytest.mark.parametrize(('prefix', 'rule', 'url'), (
('', '/', '/'),
('/', '', '/'),
('/', '/', '/'),
('/foo', '', '/foo'),
('/foo/', '', '/foo/'),
('', '/bar', '/bar'),
('/foo/', '/bar', '/foo/bar'), ('/foo/', '/bar', '/foo/bar'),
('/foo/', 'bar', '/foo/bar'), ('/foo/', 'bar', '/foo/bar'),
('/foo', '/bar', '/foo/bar'), ('/foo', '/bar', '/foo/bar'),

Loading…
Cancel
Save