Fix URL parsing for IPv6 URLs and pathless URLs
Now the following valid URLs are parsed correctly: * http://[::1]:123/foo * http://localhost?foo=bar There are still problems with the URL parsing logic but this is enough to write some unit tests.
This commit is contained in:
parent
91803cbb41
commit
06503a483b
1 changed files with 10 additions and 8 deletions
18
ddclient.in
18
ddclient.in
|
@ -2000,9 +2000,8 @@ sub geturl {
|
||||||
$proxy =~ s%^https?://%%i;
|
$proxy =~ s%^https?://%%i;
|
||||||
$url =~ s%^https?://%%i;
|
$url =~ s%^https?://%%i;
|
||||||
$server = $url;
|
$server = $url;
|
||||||
$server =~ s%/.*%%;
|
$server =~ s%[?/].*%%;
|
||||||
$url = "/" unless $url =~ m%/%;
|
$url =~ s%^[^?/]*/?%%;
|
||||||
$url =~ s%^[^/]*/%%;
|
|
||||||
|
|
||||||
opt('fw') && debug("opt(fw = %s)", opt('fw'));
|
opt('fw') && debug("opt(fw = %s)", opt('fw'));
|
||||||
$globals{'fw'} && debug("glo fw = %s", $globals{'fw'});
|
$globals{'fw'} && debug("glo fw = %s", $globals{'fw'});
|
||||||
|
@ -2022,11 +2021,14 @@ sub geturl {
|
||||||
|
|
||||||
## determine peer and port to use.
|
## determine peer and port to use.
|
||||||
$peer = $proxy || $server;
|
$peer = $proxy || $server;
|
||||||
$peer =~ s%/.*%%;
|
$peer =~ s%[?/].*%%;
|
||||||
$port = $peer;
|
if ($peer =~ /^\[([^]]+)\](?::(\d+))?$/ || $peer =~ /^([^:]+)(?::(\d+))?/) {
|
||||||
$port =~ s%^.*:%%;
|
$peer = $1;
|
||||||
$port = $default_port unless $port =~ /^\d+$/;
|
$port = $2 // $default_port;
|
||||||
$peer =~ s%:.*$%%;
|
} else {
|
||||||
|
failed("unable to extract host and port from %s", $peer);
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
$request = "$method ";
|
$request = "$method ";
|
||||||
if (!$use_ssl) {
|
if (!$use_ssl) {
|
||||||
|
|
Loading…
Reference in a new issue