Skip to content

Commit fc0e725

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

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ PHP NEWS
3838
- URI:
3939
. Fixed bug GH-20088 (Heap-use-after-free in PHP URI WHATWG parser
4040
during malformed URL processing). (lexborisov)
41+
. Fixed the distinction between an empty and a missing query/fragment
42+
when using Uri\WhatWg\Url::getQuery() and Uri\WhatWg\Url::getFragment().
43+
(kocsismate)
4144

4245
09 Oct 2025, PHP 8.5.0RC2
4346

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - fragment - only a hashmark character
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url1 = Uri\WhatWg\Url::parse("https://example.com");
9+
$url2 = $url1->withFragment("#");
10+
11+
var_dump($url1->getFragment());
12+
var_dump($url2->getFragment());
13+
var_dump($url2->toAsciiString());
14+
15+
?>
16+
--EXPECT--
17+
NULL
18+
string(0) ""
19+
string(21) "https://example.com/#"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Test Uri\WhatWg\Url component modification - query - only a question mark character
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url1 = Uri\WhatWg\Url::parse("https://example.com");
9+
$url2 = $url1->withQuery("?");
10+
11+
var_dump($url1->getQuery());
12+
var_dump($url2->getQuery());
13+
var_dump($url2->toAsciiString());
14+
15+
?>
16+
--EXPECT--
17+
NULL
18+
string(0) ""
19+
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)