Skip to content

Commit 3652096

Browse files
ndosscheVinealius
authored andcommitted
Fix phpGH-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 phpGH-14837.
1 parent 57f1add commit 3652096

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

‎ext/xml/compat.c‎

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

379-
if (ret == NULL || (parser->parser->instate != XML_PARSER_ENTITY_VALUE && parser->parser->instate != XML_PARSER_ATTRIBUTE_VALUE)) {
379+
if (ret == NULL || parser->parser->instate == XML_PARSER_CONTENT) {
380380
if (ret == NULL || ret->etype == XML_INTERNAL_GENERAL_ENTITY || ret->etype == XML_INTERNAL_PARAMETER_ENTITY || ret->etype == XML_INTERNAL_PREDEFINED_ENTITY) {
381381
/* Predefined entities will expand unless no cdata handler is present */
382382
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)