Skip to content

Commit bf70731

Browse files
committed
ext/uri: Fix the distinction between an empty and a missing query/fragment for WHATWG URLs
1 parent 81f6ba5 commit bf70731

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ PHP NEWS
3232
. Use the "includes credentials" rule of the WHATWG URL Standard to
3333
decide whether Uri\WhatWg\Url::getUsername() and ::getPassword()
3434
getters should return null or an empty string. (timwolla)
35+
. Fixed the distinction between an empty and a missing query/fragment
36+
when using Uri\WhatWg\Url::getQuery() and Uri\WhatWg\Url::getFragment().
37+
(kocsismate)
3538

3639
- Zip:
3740
. Fixed missing zend_release_fcall_info_cache on the following methods

ext/uri/tests/whatwg/modification/fragment_success_hashmark.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var_dump($url2->toAsciiString());
1515
?>
1616
--EXPECT--
1717
NULL
18-
NULL
18+
string(0) ""
1919
string(21) "https://example.com/#"

ext/uri/tests/whatwg/modification/query_success_question_mark.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ var_dump($url2->toAsciiString());
1515
?>
1616
--EXPECT--
1717
NULL
18-
NULL
18+
string(0) ""
1919
string(21) "https://example.com/?"

ext/uri/uri_parser_whatwg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static zend_result php_uri_parser_whatwg_path_read(void *uri, php_uri_component_
431431
{
432432
const lxb_url_t *lexbor_uri = uri;
433433

434-
if (lexbor_uri->path.str.length) {
434+
if (lexbor_uri->path.str.length > 0) {
435435
ZVAL_STRINGL(retval, (const char *) lexbor_uri->path.str.data, lexbor_uri->path.str.length);
436436
} else {
437437
ZVAL_EMPTY_STRING(retval);
@@ -460,7 +460,7 @@ static zend_result php_uri_parser_whatwg_query_read(void *uri, php_uri_component
460460
{
461461
const lxb_url_t *lexbor_uri = uri;
462462

463-
if (lexbor_uri->query.length) {
463+
if (lexbor_uri->query.data != NULL) {
464464
ZVAL_STRINGL(retval, (const char *) lexbor_uri->query.data, lexbor_uri->query.length);
465465
} else {
466466
ZVAL_NULL(retval);
@@ -489,7 +489,7 @@ static zend_result php_uri_parser_whatwg_fragment_read(void *uri, php_uri_compon
489489
{
490490
const lxb_url_t *lexbor_uri = uri;
491491

492-
if (lexbor_uri->fragment.length) {
492+
if (lexbor_uri->fragment.data != NULL) {
493493
ZVAL_STRINGL(retval, (const char *) lexbor_uri->fragment.data, lexbor_uri->fragment.length);
494494
} else {
495495
ZVAL_NULL(retval);

0 commit comments

Comments
 (0)