utils/decompose_uri: Support URIs containing IPv6 addresses

An URI containing a bracketed or non-bracketed IPv6 address of the form
http://[::1]:42 was previously split on the first colon for port extraction,
causing a subsequent to_count() call to fail. Harden this to check for a
digits in the last :[0-9]+ component.

Fixes #4842
This commit is contained in:
Arne Welzel 2025-09-23 10:12:45 +02:00
parent 416d997263
commit b3b0c3db7d
4 changed files with 52 additions and 8 deletions

View file

@ -117,15 +117,14 @@ function decompose_uri(uri: string): URI
}
}
if ( /:/ in s )
if ( /:[0-9]*$/ in s )
{
# Parse location and port.
parts = split_string1(s, /:/);
u$netlocation = parts[0];
if ( parts[1] != "" )
{
u$portnum = to_count(parts[1]);
}
# Input ends with a numeric port or just colon: Strip it
# for netlocation and convert any port digits into portnum.
u$netlocation = gsub(s, /:[0-9]*$/, "");
local portstr = s[|u$netlocation| + 1:];
if ( portstr != "" )
u$portnum = to_count(portstr);
}
else
{