Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a9934d4

Browse files
Making parse_server_name more consistent (#14007)
Fixes #12122
1 parent 17c031b commit a9934d4

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

changelog.d/14007.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make `parse_server_name` consistent in handling invalid server names.

synapse/util/stringutils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def parse_server_name(server_name: str) -> Tuple[str, Optional[int]]:
8686
ValueError if the server name could not be parsed.
8787
"""
8888
try:
89-
if server_name[-1] == "]":
89+
if server_name and server_name[-1] == "]":
9090
# ipv6 literal, hopefully
9191
return server_name, None
9292

@@ -123,7 +123,7 @@ def parse_and_validate_server_name(server_name: str) -> Tuple[str, Optional[int]
123123
# that nobody is sneaking IP literals in that look like hostnames, etc.
124124

125125
# look for ipv6 literals
126-
if host[0] == "[":
126+
if host and host[0] == "[":
127127
if host[-1] != "]":
128128
raise ValueError("Mismatched [...] in server name '%s'" % (server_name,))
129129

tests/http/test_endpoint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def test_parse_server_name(self):
2525
"[0abc:1def::1234]": ("[0abc:1def::1234]", None),
2626
"1.2.3.4:1": ("1.2.3.4", 1),
2727
"[0abc:1def::1234]:8080": ("[0abc:1def::1234]", 8080),
28+
":80": ("", 80),
29+
"": ("", None),
2830
}
2931

3032
for i, o in test_data.items():
@@ -42,6 +44,7 @@ def test_validate_bad_server_names(self):
4244
"newline.com\n",
4345
".empty-label.com",
4446
"1234:5678:80", # too many colons
47+
":80",
4548
]
4649
for i in test_data:
4750
try:

0 commit comments

Comments
 (0)