-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Add RFC 3986 and WHATWG compliant URL parsing support #14461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
196957b
0334e22
a09a457
3abdb0a
1445e55
e4de160
77184ce
3b0449d
5f90823
b7011b8
f20842a
c88e92b
c743ead
19b7180
fb0c929
cf7ca4e
9de1271
db3b79d
feefccf
190bbfd
d1df694
0d1fc02
df1d0b9
e8261f7
7530dd9
b75cc5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,24 +67,13 @@ const uri_handler_t lexbor_uri_handler = { | |
return SUCCESS; \ | ||
} while (0) | ||
|
||
#define LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(start, len, read_mode, retval) do { \ | ||
#define LEXBOR_READ_ASCII_URI_COMPONENT(start, len, read_mode, retval) do { \ | ||
switch (read_mode) { \ | ||
case URI_COMPONENT_READ_RAW: \ | ||
ZVAL_STRINGL(retval, (const char *) start, len); \ | ||
break; \ | ||
case URI_COMPONENT_READ_RAW: /* Intentional fallthrough */ \ | ||
case URI_COMPONENT_READ_NORMALIZED_UNICODE: /* Intentional fallthrough */ \ | ||
case URI_COMPONENT_READ_NORMALIZED_ASCII: { \ | ||
lexbor_str_t *str = lexbor_str_create(); \ | ||
lxb_url_host_opt_t opt; \ | ||
lxb_status_t result = lxb_url_percent_decode(start, start + len, \ | ||
str, lexbor_uri->mraw, &opt \ | ||
); \ | ||
if (result != LXB_STATUS_OK) { \ | ||
return FAILURE; \ | ||
} \ | ||
ZVAL_STRINGL(retval, (const char *) str->data, str->length); \ | ||
lexbor_str_destroy(str, lexbor_uri->mraw, true); \ | ||
break; \ | ||
ZVAL_STRINGL(retval, (const char *) start, len); \ | ||
break; \ | ||
} \ | ||
EMPTY_SWITCH_DEFAULT_CASE() \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. given the EMPTY_SWITCH_DEFAULT_CASE() and the fact that all of the cases fall through, what is the point of even having a |
||
} \ | ||
|
@@ -291,7 +280,7 @@ static zend_result lexbor_read_username(const uri_internal_t *internal_uri, uri_ | |
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri; | ||
|
||
if (lexbor_uri->username.length) { | ||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->username.data, lexbor_uri->username.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->username.data, lexbor_uri->username.length, read_mode, retval); | ||
} else { | ||
ZVAL_NULL(retval); | ||
} | ||
|
@@ -316,7 +305,7 @@ static zend_result lexbor_read_password(const uri_internal_t *internal_uri, uri_ | |
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri; | ||
|
||
if (lexbor_uri->password.length > 0) { | ||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->password.data, lexbor_uri->password.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->password.data, lexbor_uri->password.length, read_mode, retval); | ||
} else { | ||
ZVAL_NULL(retval); | ||
} | ||
|
@@ -427,9 +416,9 @@ static zend_result lexbor_read_path(const uri_internal_t *internal_uri, uri_comp | |
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri; | ||
|
||
if (lexbor_uri->path.opaque) { | ||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval); | ||
} else if (lexbor_uri->path.str.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these two blocks look the same - can they be combined? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, nice catch |
||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->path.str.data, lexbor_uri->path.str.length, read_mode, retval); | ||
} else { | ||
ZVAL_EMPTY_STRING(retval); | ||
} | ||
|
@@ -454,7 +443,7 @@ static zend_result lexbor_read_query(const uri_internal_t *internal_uri, uri_com | |
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri; | ||
|
||
if (lexbor_uri->query.length) { | ||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->query.data, lexbor_uri->query.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->query.data, lexbor_uri->query.length, read_mode, retval); | ||
} else { | ||
ZVAL_NULL(retval); | ||
} | ||
|
@@ -479,7 +468,7 @@ static zend_result lexbor_read_fragment(const uri_internal_t *internal_uri, uri_ | |
lxb_url_t *lexbor_uri = (lxb_url_t *) internal_uri->uri; | ||
|
||
if (lexbor_uri->fragment.length) { | ||
LEXBOR_READ_PERCENT_ENCODED_URI_COMPONENT(lexbor_uri->fragment.data, lexbor_uri->fragment.length, read_mode, retval); | ||
LEXBOR_READ_ASCII_URI_COMPONENT(lexbor_uri->fragment.data, lexbor_uri->fragment.length, read_mode, retval); | ||
} else { | ||
ZVAL_NULL(retval); | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,23 +5,18 @@ uri | |
--FILE-- | ||
<?php | ||
|
||
function callGetters($uri) | ||
function callRfc3986Getters($uri) | ||
{ | ||
var_dump($uri->getScheme()); | ||
if ($uri instanceof Uri\Rfc3986\Uri) { | ||
var_dump($uri->getRawScheme()); | ||
} | ||
var_dump($uri->getRawScheme()); | ||
var_dump($uri->getUsername()); | ||
var_dump($uri->getRawUsername()); | ||
var_dump($uri->getPassword()); | ||
var_dump($uri->getRawPassword()); | ||
if ($uri instanceof Uri\Rfc3986\Uri) { | ||
var_dump($uri->getHost()); | ||
var_dump($uri->getRawHost()); | ||
} else { | ||
var_dump($uri->getAsciiHost()); | ||
var_dump($uri->getUnicodeHost()); | ||
} | ||
var_dump($uri->getUserInfo()); | ||
var_dump($uri->getRawUserInfo()); | ||
var_dump($uri->getHost()); | ||
var_dump($uri->getRawHost()); | ||
var_dump($uri->getPort()); | ||
var_dump($uri->getPath()); | ||
var_dump($uri->getRawPath()); | ||
|
@@ -31,13 +26,26 @@ function callGetters($uri) | |
var_dump($uri->getRawFragment()); | ||
} | ||
|
||
function callWhatWgGetters($uri) | ||
{ | ||
var_dump($uri->getScheme()); | ||
var_dump($uri->getRawUsername()); | ||
var_dump($uri->getRawPassword()); | ||
var_dump($uri->getAsciiHost()); | ||
var_dump($uri->getUnicodeHost()); | ||
var_dump($uri->getPort()); | ||
var_dump($uri->getRawPath()); | ||
var_dump($uri->getRawQuery()); | ||
var_dump($uri->getRawFragment()); | ||
} | ||
|
||
$uri = Uri\Rfc3986\Uri::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); | ||
callGetters($uri); | ||
callRfc3986Getters($uri); | ||
|
||
echo "\n"; | ||
|
||
$url = Uri\WhatWg\Url::parse("https://username:[email protected]:8080/pathname1/pathname2/pathname3?query=true#hash-exists"); | ||
callGetters($url); | ||
callWhatWgGetters($url); | ||
|
||
?> | ||
--EXPECT-- | ||
|
@@ -47,6 +55,8 @@ string(8) "username" | |
string(8) "username" | ||
string(8) "password" | ||
string(8) "password" | ||
string(17) "username:password" | ||
string(17) "username:password" | ||
string(14) "www.google.com" | ||
string(14) "www.google.com" | ||
int(8080) | ||
|
@@ -59,15 +69,10 @@ string(11) "hash-exists" | |
|
||
string(5) "https" | ||
string(8) "username" | ||
string(8) "username" | ||
string(8) "password" | ||
string(8) "password" | ||
string(14) "www.google.com" | ||
string(14) "www.google.com" | ||
int(8080) | ||
string(30) "/pathname1/pathname2/pathname3" | ||
string(30) "/pathname1/pathname2/pathname3" | ||
string(10) "query=true" | ||
string(10) "query=true" | ||
string(11) "hash-exists" | ||
string(11) "hash-exists" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.