Skip to content

Commit a6a6810

Browse files
authored
Merge pull request pallets#2748 from pallets/fix-bp-route
Fix blueprint route for ""
2 parents 3fd7abe + b21b4d1 commit a6a6810

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

flask/blueprints.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
:license: BSD, see LICENSE for more details.
1111
"""
1212
from functools import update_wrapper
13+
from werkzeug.urls import url_join
1314

1415
from .helpers import _PackageBoundObject, _endpoint_from_view_func
1516

@@ -49,8 +50,6 @@ def __init__(self, blueprint, app, options, first_registration):
4950
url_prefix = self.options.get('url_prefix')
5051
if url_prefix is None:
5152
url_prefix = self.blueprint.url_prefix
52-
if url_prefix:
53-
url_prefix = url_prefix.rstrip('/')
5453
#: The prefix that should be used for all URLs defined on the
5554
#: blueprint.
5655
self.url_prefix = url_prefix
@@ -66,7 +65,11 @@ def add_url_rule(self, rule, endpoint=None, view_func=None, **options):
6665
blueprint's name.
6766
"""
6867
if self.url_prefix is not None:
69-
rule = '/'.join((self.url_prefix, rule.lstrip('/')))
68+
if rule:
69+
rule = '/'.join((
70+
self.url_prefix.rstrip('/'), rule.lstrip('/')))
71+
else:
72+
rule = self.url_prefix
7073
options.setdefault('subdomain', self.subdomain)
7174
if endpoint is None:
7275
endpoint = _endpoint_from_view_func(view_func)

tests/test_blueprints.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ def bp_forbidden():
116116

117117

118118
@pytest.mark.parametrize(('prefix', 'rule', 'url'), (
119+
('', '/', '/'),
120+
('/', '', '/'),
121+
('/', '/', '/'),
122+
('/foo', '', '/foo'),
123+
('/foo/', '', '/foo/'),
124+
('', '/bar', '/bar'),
119125
('/foo/', '/bar', '/foo/bar'),
120126
('/foo/', 'bar', '/foo/bar'),
121127
('/foo', '/bar', '/foo/bar'),

0 commit comments

Comments
 (0)