only strip one slash when registering blueprint
Before adoption: this commit came in with the history the project adopted, so no landing records it.
add test and changelog
authored by David Lord · committed by David Lord · parent 0887245 · Browse files · 3 files·+20 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+20 added−4 removed
- tests:+14 added−1 removed
- other:+6 added−3 removed
Provenance
- Commit
401423d- Tree
8daa4a4- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
0887245
3 files changed+20 added−4 removed
modified:flask/blueprints.py+3 added-3 removed
7 unmodified lines8 9 :copyright: © 2010 by the Pallets team.10 :license: BSD, see LICENSE for more details.11 """12-13-import re12 from functools import update_wrapper13 14 from .helpers import _PackageBoundObject, _endpoint_from_view_func15 35 unmodified lines51 url_prefix = self.blueprint.url_prefix52 53 #: The prefix that should be used for all URLs defined on the54 #: blueprint.55+ if url_prefix and url_prefix[-1] == '/':56+ url_prefix = url_prefix[:-1]57+58 self.url_prefix = url_prefix59 60 #: A dictionary with URL defaults that is added to each and every61 #: URL that was defined with the blueprint.6 unmodified lines68 blueprint's name.69 """70 if self.url_prefix:71 rule = self.url_prefix + rule71- rule = re.sub('/+', '/', rule)72 options.setdefault('subdomain', self.subdomain)73 if endpoint is None:74 endpoint = _endpoint_from_view_func(view_func)75 defaults = self.url_defaults372 unmodified linesmodified:tests/test_blueprints.py+14 added-1 removed
112 unmodified lines113 assert client.get('/forbidden').data == b'you shall not pass'114 assert client.get('/nope').data == b'you shall not pass'115 116 117-def test_blueprint_url_definitions(app, client):117+def test_blueprint_prefix_slash(app, client):118+ bp = flask.Blueprint('test', __name__, url_prefix='/bar/')119+120+ @bp.route('/foo')121+ def foo():122+ return '', 204123+124+ app.register_blueprint(bp)125+ app.register_blueprint(bp, url_prefix='/spam/')126+ assert client.get('/bar/foo').status_code == 204127+ assert client.get('/spam/foo').status_code == 204128+129+130+def test_blueprint_url_defaults(app, client):131 bp = flask.Blueprint('test', __name__)132 133 @bp.route('/foo', defaults={'baz': 42})134 def foo(bar, baz):708 unmodified linesmodified:CHANGES.rst+3 added
141 unmodified lines142 - Subdomain matching is disabled by default and setting143 :data:`SERVER_NAME` does not implicily enable it. It can be enabled by144 passing ``subdomain_matching=True`` to the ``Flask`` constructor.145 (`#2635`_)146+- A single trailing slash is stripped from the blueprint ``url_prefix``147+ when it is registered with the app. (`#2629`_)148 149 .. _pallets/meta#24: https://github.com/pallets/meta/issues/24150 .. _#1421: https://github.com/pallets/flask/issues/1421151 .. _#1489: https://github.com/pallets/flask/pull/148935 unmodified lines187 .. _#2606: https://github.com/pallets/flask/pull/2606188 .. _#2607: https://github.com/pallets/flask/pull/2607189 .. _#2636: https://github.com/pallets/flask/pull/2636190 .. _#2635: https://github.com/pallets/flask/pull/2635191+.. _#2629: https://github.com/pallets/flask/pull/2629192 193 194 Version 0.12.2195 --------------618 unmodified lines