Skip to content
Myr

merge slashes between blueprint prefix and rule

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent 5239458 · Browse files · 2 files+15 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+15 added−12 removed

  • tests:+12 added−7 removed
  • other:+3 added−5 removed

2 files+15 added−12 removed

modified:flask/blueprints.py+3 added-5 removed
47 unmodified lines
4849 url_prefix = self.options.get('url_prefix')50 if url_prefix is None:51 url_prefix = self.blueprint.url_prefix5252 if url_prefix:53 url_prefix = url_prefix.rstrip('/')54 #: The prefix that should be used for all URLs defined on the55 #: blueprint.55 if url_prefix and url_prefix[-1] == '/':56 url_prefix = url_prefix[:-1]5756 self.url_prefix = url_prefix5758 #: A dictionary with URL defaults that is added to each and every59 #: URL that was defined with the blueprint.
5 unmodified lines
65 to the application. The endpoint is automatically prefixed with the66 blueprint's name.67 """68 if self.url_prefix:71 rule = self.url_prefix + rule69 rule = '/'.join((self.url_prefix, rule.lstrip('/')))70 options.setdefault('subdomain', self.subdomain)71 if endpoint is None:72 endpoint = _endpoint_from_view_func(view_func)73 defaults = self.url_defaults
372 unmodified lines
modified:tests/test_blueprints.py+12 added-7 removed
113 unmodified lines
114 assert client.get('/forbidden').data == b'you shall not pass'115 assert client.get('/nope').data == b'you shall not pass'116117118@pytest.mark.parametrize(('prefix', 'rule', 'url'), (119 ('/foo/', '/bar', '/foo/bar'),120 ('/foo/', 'bar', '/foo/bar'),121 ('/foo', '/bar', '/foo/bar'),122 ('/foo/', '//bar', '/foo/bar'),123 ('/foo//', '/bar', '/foo/bar'),124))118def test_blueprint_prefix_slash(app, client):119 bp = flask.Blueprint('test', __name__, url_prefix='/bar/')125def test_blueprint_prefix_slash(app, client, prefix, rule, url):126 bp = flask.Blueprint('test', __name__, url_prefix=prefix)127121 @bp.route('/foo')122 def foo():128 @bp.route(rule)129 def index():130 return '', 204131132 app.register_blueprint(bp)126 app.register_blueprint(bp, url_prefix='/spam/')127 assert client.get('/bar/foo').status_code == 204133 assert client.get(url).status_code == 204128 assert client.get('/spam/foo').status_code == 204134135136def test_blueprint_url_defaults(app, client):137 bp = flask.Blueprint('test', __name__)
713 unmodified lines