From cf5bec547aee2fd8406558eb6fa6adb836ba065f Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 19 Nov 2024 09:19:04 +0100 Subject: [PATCH] Only match SERVER_NAME subdomains when explicitly asked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This change has been introduced in Flask 3.1.0 and actually makes sense: SERVER_NAME now matches subdomains when subdomain_matching is set. Let’s follow the same rule for Flask-WeasyPrint. --- flask_weasyprint/__init__.py | 7 ++++--- tests/test_flask_weasyprint.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/flask_weasyprint/__init__.py b/flask_weasyprint/__init__.py index 2851f73..53bd6cc 100644 --- a/flask_weasyprint/__init__.py +++ b/flask_weasyprint/__init__.py @@ -20,8 +20,9 @@ def make_flask_url_dispatcher(): has returned. Dispatch to the context’s app URLs below the context’s root URL. If the - application has a ``SERVER_NAME`` :doc:`configuration `, also - accept URLs that have that domain name or a subdomain thereof. + application has a ``SERVER_NAME`` :doc:`configuration ` and + ``subdomain_matching`` is set, also accept URLs that have that domain name + or a subdomain thereof. """ def parse_netloc(netloc): @@ -33,7 +34,7 @@ def parse_netloc(netloc): root_path = request.script_root server_name = app.config.get('SERVER_NAME') - if server_name: + if server_name and app.subdomain_matching: hostname, port = parse_netloc(server_name) def accept(url): diff --git a/tests/test_flask_weasyprint.py b/tests/test_flask_weasyprint.py index d9afdf7..3bfe5d0 100644 --- a/tests/test_flask_weasyprint.py +++ b/tests/test_flask_weasyprint.py @@ -111,7 +111,7 @@ def add_redirect(old_url, new_url): def test_dispatcher(): - app = Flask(__name__) + app = Flask(__name__, subdomain_matching=True) app.config['PROPAGATE_EXCEPTIONS'] = True @app.route('/')