Skip to content

Commit 67259e4

Browse files
committed
Fix GH-14834: Error installing PHP when --with-pear is used
libxml2 2.13 makes changes to how the parsing state is set, update our code accordingly. In particular, it started reporting entities within attributes, while it should only report entities inside text nodes. Closes GH-14837.
1 parent a66afbb commit 67259e4

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Diff for: NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ PHP NEWS
4848

4949
- XML:
5050
. Move away from to-be-deprecated libxml fields. (nielsdos)
51+
. Fixed bug GH-14834 (Error installing PHP when --with-pear is used).
52+
(nielsdos)
5153

5254
04 Jul 2024, PHP 8.2.21
5355

Diff for: ext/xml/compat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ _get_entity(void *user, const xmlChar *name)
375375
if (ret == NULL)
376376
ret = xmlGetDocEntity(parser->parser->myDoc, name);
377377

378-
if (ret == NULL || (parser->parser->instate != XML_PARSER_ENTITY_VALUE && parser->parser->instate != XML_PARSER_ATTRIBUTE_VALUE)) {
378+
if (ret == NULL || parser->parser->instate == XML_PARSER_CONTENT) {
379379
if (ret == NULL || ret->etype == XML_INTERNAL_GENERAL_ENTITY || ret->etype == XML_INTERNAL_PARAMETER_ENTITY || ret->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
380380
/* Predefined entities will expand unless no cdata handler is present */
381381
if (parser->h_default && ! (ret && ret->etype == XML_INTERNAL_PREDEFINED_ENTITY && parser->h_cdata)) {

Diff for: ext/xml/tests/gh14834.phpt

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
GH-14834 (Error installing PHP when --with-pear is used)
3+
--EXTENSIONS--
4+
xml
5+
--FILE--
6+
<?php
7+
$xml = <<<XML
8+
<?xml version="1.0" encoding="UTF-8"?>
9+
<!DOCTYPE root [
10+
<!ENTITY foo "ent">
11+
]>
12+
<root>
13+
<element hint="hello&apos;world">&foo;<![CDATA[ &amp; ]]><?x &amp; ?></element>
14+
</root>
15+
XML;
16+
17+
$parser = xml_parser_create();
18+
xml_set_character_data_handler($parser, function($_, $data) {
19+
var_dump($data);
20+
});
21+
xml_parse($parser, $xml, true);
22+
?>
23+
--EXPECT--
24+
string(3) "
25+
"
26+
string(3) "ent"
27+
string(7) " &amp; "
28+
string(1) "
29+
"

0 commit comments

Comments
 (0)