Skip to content
Myr

Fix nested blueprint url_prefix

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

This fixes the case where the blueprint is registered with a url_prefix but any child blueprints have no prefixes.

authored by pgjones · committed by pgjones · parent f64fff6 · Browse files · 2 files+16 added−0 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+16 added−0 removed

  • tests:+14 added−0 removed
  • other:+2 added−0 removed

2 files+16 added−0 removed

modified:src/flask/blueprints.py+2 added
352 unmodified lines
353 if state.url_prefix is not None and bp_url_prefix is not None:354 bp_options["url_prefix"] = (355 state.url_prefix.rstrip("/") + "/" + bp_url_prefix.lstrip("/")356 )357 else:358 bp_options["url_prefix"] = state.url_prefix359360 bp_options["name_prefix"] = options.get("name_prefix", "") + self.name + "."361 blueprint.register(app, bp_options)362
190 unmodified lines
modified:tests/test_blueprints.py+14 added
866 unmodified lines
867 assert client.get("/parent/").data == b"Parent"868 assert client.get("/parent/child/").data == b"Child"869 assert client.get("/parent/child/grandchild/").data == b"Grandchild"870 assert client.get("/parent/child/orange/").data == b"Apple"871872873def test_nested_blueprint_url_prefix_only_parent_prefix(app, client):874 parent = flask.Blueprint("parent", __name__)875 child = flask.Blueprint("child", __name__)876877 @child.route("/child-endpoint")878 def child_index():879 return "Child"880881 parent.register_blueprint(child)882 app.register_blueprint(parent, url_prefix="/parent")883884 assert client.get("/parent/child-endpoint").data == b"Child"