Skip to content
Myr

Fix IPv6 server name parsing

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

authored by lkk7 · committed by David Lord · parent de8429f · Browse files · 2 files+8 added−4 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+8 added−4 removed

  • tests:+1 added−0 removed
  • other:+7 added−4 removed

2 files+8 added−4 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: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