Skip to content
Myr

Fix `.partition(":")` usage on potential IPv6 addresses (#6096)

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

authored by David Lord · committed by GitHub · parents 514fc6b, 7203fea · Browse files · 4 files+23 added−5 removed
This commit

State

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

Diff stats

4 files+23 added−5 removed

  • tests:+15 added−0 removed
  • other:+8 added−5 removed

4 files+23 added−5 removed

modified:src/flask/app.py+7 added-4 removed
10 unmodified lines
11from inspect import iscoroutinefunction12from itertools import chain13from types import TracebackType14from urllib.parse import quote as _url_quote15from urllib.parse import urlsplit1617import click18from werkzeug.datastructures import Headers19from werkzeug.datastructures import ImmutableDict
701 unmodified lines
721 server_name = self.config.get("SERVER_NAME")722 sn_host = sn_port = None723724 if server_name:724 sn_host, _, sn_port = server_name.partition(":")725 server_url = urlsplit(f"//{server_name}")726 sn_host = server_url.hostname727 sn_port = server_url.port728729 if not host:730 if sn_host:731 host = sn_host
1 unmodified line
733 host = "127.0.0.1"734735 if port or port == 0:736 port = int(port)734 elif sn_port:735 port = int(sn_port)737 elif sn_port is not None:738 port = sn_port739 else:740 port = 5000741742 options.setdefault("use_reloader", self.debug)
4 unmodified lines
747748 from werkzeug.serving import run_simple749750 try:748 run_simple(t.cast(str, host), port, self, **options)751 run_simple(host, port, self, **options)752 finally:753 # reset the first request information if the development server754 # reset normally. This makes it possible to restart the server755 # without reloader and that stuff from an interactive shell.
873 unmodified lines
modified:src/flask/testing.py+1 added-1 removed
175 unmodified lines
176 with ctx:177 app.session_interface.save_session(app, sess, resp)178179 self._update_cookies_from_response(180 ctx.request.host.partition(":")[0],180 urlsplit(ctx.request.host_url).hostname or "localhost",181 ctx.request.path,182 resp.headers.getlist("Set-Cookie"),183 )184
114 unmodified lines
modified:tests/test_basic.py+1 added
1908 unmodified lines
1909 ("localhost", 80, "pocoo.org:8080", "localhost", 80),1910 ("localhost", 0, "localhost:8080", "localhost", 0),1911 (None, None, "localhost:8080", "localhost", 8080),1912 (None, None, "localhost:0", "localhost", 0),1913 (None, None, "[::1]:8080", "::1", 8080),1914 ),1915)1916def test_run_from_config(1917 monkeypatch, host, port, server_name, expect_host, expect_port, app
54 unmodified lines
modified:tests/test_testing.py+14 added
169 unmodified lines
170 assert len(sess) == 1171 assert sess["foo"] == [42]172173174def test_session_transaction_ipv6(app):175 base_url = "http://[::1]:8000/"176 client = app.test_client()177178 @app.get("/")179 def index():180 return str(flask.session.get("value"))181182 with client.session_transaction(base_url=base_url) as sess:183 sess["value"] = 42184185 assert client.get("/", base_url=base_url).text == "42"186187188def test_session_transactions_no_null_sessions():189 app = flask.Flask(__name__)190191 with app.test_client() as c:
207 unmodified lines