Skip to content

Commit b3e0039

Browse files
nielsdosgithub-actions[bot]
authored andcommitted
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 81e4100 commit b3e0039

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ext/xml/compat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ _get_entity(void *user, const xmlChar *name)
383383
if (ret == NULL)
384384
ret = xmlGetDocEntity(parser->parser->myDoc, name);
385385

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

ext/xml/tests/gh14834.phpt

Lines changed: 29 additions & 0 deletions
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)