This commit is contained in:
Nikita Popov 2016-10-08 01:04:22 +02:00
parent bc3a0b82b8
commit b061fa909d
11 changed files with 49 additions and 56 deletions

View file

@ -0,0 +1,30 @@
--TEST--
Bug #73192: parse_url return wrong hostname
--FILE--
<?php
var_dump(parse_url("http://example.com:80#@google.com/"));
var_dump(parse_url("http://example.com:80?@google.com/"));
?>
--EXPECT--
array(4) {
["scheme"]=>
string(4) "http"
["host"]=>
string(11) "example.com"
["port"]=>
int(80)
["fragment"]=>
string(12) "@google.com/"
}
array(4) {
["scheme"]=>
string(4) "http"
["host"]=>
string(11) "example.com"
["port"]=>
int(80)
["query"]=>
string(12) "@google.com/"
}

View file

@ -763,25 +763,9 @@ echo "Done";
int(6) int(6)
} }
--> http://?:/: array(3) { --> http://?:/: bool(false)
["scheme"]=>
string(4) "http"
["host"]=>
string(1) "?"
["path"]=>
string(1) "/"
}
--> http://@?:/: array(4) { --> http://@?:/: bool(false)
["scheme"]=>
string(4) "http"
["host"]=>
string(1) "?"
["user"]=>
string(0) ""
["path"]=>
string(1) "/"
}
--> file:///:: array(2) { --> file:///:: array(2) {
["scheme"]=> ["scheme"]=>

View file

@ -98,8 +98,8 @@ echo "Done";
--> http://::? : string(4) "http" --> http://::? : string(4) "http"
--> http://::# : string(4) "http" --> http://::# : string(4) "http"
--> x://::6.5 : string(1) "x" --> x://::6.5 : string(1) "x"
--> http://?:/ : string(4) "http" --> http://?:/ : bool(false)
--> http://@?:/ : string(4) "http" --> http://@?:/ : bool(false)
--> file:///: : string(4) "file" --> file:///: : string(4) "file"
--> file:///a:/ : string(4) "file" --> file:///a:/ : string(4) "file"
--> file:///ab:/ : string(4) "file" --> file:///ab:/ : string(4) "file"

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : string(1) ":" --> http://::? : string(1) ":"
--> http://::# : string(1) ":" --> http://::# : string(1) ":"
--> x://::6.5 : string(1) ":" --> x://::6.5 : string(1) ":"
--> http://?:/ : string(1) "?" --> http://?:/ : bool(false)
--> http://@?:/ : string(1) "?" --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : int(6) --> x://::6.5 : int(6)
--> http://?:/ : NULL --> http://?:/ : bool(false)
--> http://@?:/ : NULL --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : NULL --> x://::6.5 : NULL
--> http://?:/ : NULL --> http://?:/ : bool(false)
--> http://@?:/ : string(0) "" --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : NULL --> x://::6.5 : NULL
--> http://?:/ : NULL --> http://?:/ : bool(false)
--> http://@?:/ : NULL --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : NULL --> x://::6.5 : NULL
--> http://?:/ : string(1) "/" --> http://?:/ : bool(false)
--> http://@?:/ : string(1) "/" --> http://@?:/ : bool(false)
--> file:///: : string(2) "/:" --> file:///: : string(2) "/:"
--> file:///a:/ : string(3) "a:/" --> file:///a:/ : string(3) "a:/"
--> file:///ab:/ : string(5) "/ab:/" --> file:///ab:/ : string(5) "/ab:/"

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : NULL --> x://::6.5 : NULL
--> http://?:/ : NULL --> http://?:/ : bool(false)
--> http://@?:/ : NULL --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -97,8 +97,8 @@ echo "Done";
--> http://::? : NULL --> http://::? : NULL
--> http://::# : NULL --> http://::# : NULL
--> x://::6.5 : NULL --> x://::6.5 : NULL
--> http://?:/ : NULL --> http://?:/ : bool(false)
--> http://@?:/ : NULL --> http://@?:/ : bool(false)
--> file:///: : NULL --> file:///: : NULL
--> file:///a:/ : NULL --> file:///a:/ : NULL
--> file:///ab:/ : NULL --> file:///ab:/ : NULL

View file

@ -217,28 +217,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length)
goto nohost; goto nohost;
} }
e = ue; e = s + strcspn(s, "/?#");
if (!(p = memchr(s, '/', (ue - s)))) {
char *query, *fragment;
query = memchr(s, '?', (ue - s));
fragment = memchr(s, '#', (ue - s));
if (query && fragment) {
if (query > fragment) {
e = fragment;
} else {
e = query;
}
} else if (query) {
e = query;
} else if (fragment) {
e = fragment;
}
} else {
e = p;
}
/* check for login and password */ /* check for login and password */
if ((p = zend_memrchr(s, '@', (e-s)))) { if ((p = zend_memrchr(s, '@', (e-s)))) {