Skip to content

Commit

Permalink
Only match SERVER_NAME subdomains when explicitly asked
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
liZe committed Nov 19, 2024
1 parent 3ee20b7 commit cf5bec5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions flask_weasyprint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <flask:config>`, also
accept URLs that have that domain name or a subdomain thereof.
application has a ``SERVER_NAME`` :doc:`configuration <flask:config>` and
``subdomain_matching`` is set, also accept URLs that have that domain name
or a subdomain thereof.
"""
def parse_netloc(netloc):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flask_weasyprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('/')
Expand Down

0 comments on commit cf5bec5

Please sign in to comment.