Skip to content

Commit 13d63d6

Browse files
committed
Fix GH-20771: Assertion failure when getUnicodeHost() returns empty string
If nothing was added to a smart_str, the interned empty string is returned, and therefore ZVAL_NEW_STR is wrong as it'll set the REFCOUNTED flag. Closes GH-20773.
1 parent 0eb6a4d commit 13d63d6

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ PHP NEWS
5050
- Standard:
5151
. Fix error check for proc_open() command. (ndossche)
5252

53+
- URI:
54+
. Fixed bug GH-20771 (Assertion failure when getUnicodeHost() returns
55+
empty string). (ndossche)
56+
5357
18 Dec 2025, PHP 8.5.1
5458

5559
- Core:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20771 (Assertion failure when getUnicodeHost() returns empty string)
3+
--EXTENSIONS--
4+
uri
5+
--FILE--
6+
<?php
7+
8+
$url = Uri\WhatWg\Url::parse('test://');
9+
10+
var_dump($url->getUnicodeHost());
11+
12+
?>
13+
--EXPECT--
14+
string(0) ""

ext/uri/uri_parser_whatwg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static zend_result php_uri_parser_whatwg_host_read(void *uri, php_uri_component_
365365
lxb_url_serialize_host_unicode(&lexbor_idna, &lexbor_uri->host, serialize_to_smart_str_callback, &host_str);
366366
lxb_unicode_idna_clean(&lexbor_idna);
367367

368-
ZVAL_NEW_STR(retval, smart_str_extract(&host_str));
368+
ZVAL_STR(retval, smart_str_extract(&host_str));
369369
break;
370370
}
371371
case PHP_URI_COMPONENT_READ_MODE_NORMALIZED_ASCII:

0 commit comments

Comments
 (0)