Skip to content
Myr

Fix subdomain inheritance for nested blueprints.

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

Fixes #4834

authored by Josh Michael Karamuth · committed by pgjones · parent fa1ee70 · Browse files · 2 files+56 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+56 added−0 removed

  • tests:+47 added−0 removed
  • other:+9 added−0 removed

2 files+56 added−0 removed

modified:src/flask/blueprints.py+9 added
451 unmodified lines
452453 for blueprint, bp_options in self._blueprints:454 bp_options = bp_options.copy()455 bp_url_prefix = bp_options.get("url_prefix")456 bp_subdomain = bp_options.get("subdomain")457458 if bp_subdomain is None:459 bp_subdomain = blueprint.subdomain460461 if state.subdomain is not None and bp_subdomain is None:462 bp_options["subdomain"] = state.subdomain463 elif bp_subdomain is not None:464 bp_options["subdomain"] = bp_subdomain465466 if bp_url_prefix is None:467 bp_url_prefix = blueprint.url_prefix468469 if state.url_prefix is not None and bp_url_prefix is not None:
246 unmodified lines
modified:tests/test_blueprints.py+47 added
948 unmodified lines
949 response = client.get("/parent/child/")950 assert response.status_code == 200951952953def test_nesting_subdomains(app, client) -> None:954 subdomain = "api"955 parent = flask.Blueprint("parent", __name__)956 child = flask.Blueprint("child", __name__)957958 @child.route("/child/")959 def index():960 return "child"961962 parent.register_blueprint(child)963 app.register_blueprint(parent, subdomain=subdomain)964965 client.allow_subdomain_redirects = True966967 domain_name = "domain.tld"968 app.config["SERVER_NAME"] = domain_name969 response = client.get("/child/", base_url="http://api." + domain_name)970971 assert response.status_code == 200972973974def test_child_overrides_parent_subdomain(app, client) -> None:975 child_subdomain = "api"976 parent_subdomain = "parent"977 parent = flask.Blueprint("parent", __name__)978 child = flask.Blueprint("child", __name__, subdomain=child_subdomain)979980 @child.route("/")981 def index():982 return "child"983984 parent.register_blueprint(child)985 app.register_blueprint(parent, subdomain=parent_subdomain)986987 client.allow_subdomain_redirects = True988989 domain_name = "domain.tld"990 app.config["SERVER_NAME"] = domain_name991 response = client.get("/", base_url=f"http://{child_subdomain}.{domain_name}")992993 assert response.status_code == 200994995 response = client.get("/", base_url=f"http://{parent_subdomain}.{domain_name}")996997 assert response.status_code == 4049989991000def test_unique_blueprint_names(app, client) -> None:1001 bp = flask.Blueprint("bp", __name__)1002 bp2 = flask.Blueprint("bp", __name__)1003
49 unmodified lines