Skip to content

Commit 3868a1f

Browse files
committed
ext/uri: Fix the distinction between an empty and a missing query/fragment for WHATWG URLs
1 parent 2e0ab27 commit 3868a1f

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ PHP NEWS
2626
. Fixed bug GH-19798: XP_SOCKET XP_SSL (Socket stream modules): Incorrect
2727
condition for Win32/Win64. (Jakub Zelenka)
2828

29+
- URI:
30+
. Fixed the distinction between an empty and a missing query/fragment
31+
when using Uri\WhatWg\Url::getQuery() and Uri\WhatWg\Url::getFragment().
32+
(kocsismate)
33+
2934
- Zip:
3035
. Fixed missing zend_release_fcall_info_cache on the following methods
3136
ZipArchive::registerProgressCallback() and ZipArchive::registerCancelCallback()

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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static zend_result php_uri_parser_whatwg_username_read(void *uri, php_uri_compon
278278
{
279279
const lxb_url_t *lexbor_uri = uri;
280280

281-
if (lexbor_uri->username.length) {
281+
if (lexbor_uri->username.length > 0) {
282282
ZVAL_STRINGL(retval, (const char *) lexbor_uri->username.data, lexbor_uri->username.length);
283283
} else {
284284
ZVAL_NULL(retval);
@@ -425,7 +425,7 @@ static zend_result php_uri_parser_whatwg_path_read(void *uri, php_uri_component_
425425
{
426426
const lxb_url_t *lexbor_uri = uri;
427427

428-
if (lexbor_uri->path.str.length) {
428+
if (lexbor_uri->path.str.length > 0) {
429429
ZVAL_STRINGL(retval, (const char *) lexbor_uri->path.str.data, lexbor_uri->path.str.length);
430430
} else {
431431
ZVAL_EMPTY_STRING(retval);
@@ -454,7 +454,7 @@ static zend_result php_uri_parser_whatwg_query_read(void *uri, php_uri_component
454454
{
455455
const lxb_url_t *lexbor_uri = uri;
456456

457-
if (lexbor_uri->query.length) {
457+
if (lexbor_uri->query.data != NULL) {
458458
ZVAL_STRINGL(retval, (const char *) lexbor_uri->query.data, lexbor_uri->query.length);
459459
} else {
460460
ZVAL_NULL(retval);
@@ -483,7 +483,7 @@ static zend_result php_uri_parser_whatwg_fragment_read(void *uri, php_uri_compon
483483
{
484484
const lxb_url_t *lexbor_uri = uri;
485485

486-
if (lexbor_uri->fragment.length) {
486+
if (lexbor_uri->fragment.data != NULL) {
487487
ZVAL_STRINGL(retval, (const char *) lexbor_uri->fragment.data, lexbor_uri->fragment.length);
488488
} else {
489489
ZVAL_NULL(retval);

0 commit comments

Comments
 (0)