Skip to content

Commit 7c0dfc5

Browse files
committed
Fix GH-11160: Few tests failed building with new libxml 2.11.0
It's possible to categorise the failures into 2 categories: - Changed error message. In this case we either duplicate the test and modify the error message. Or if the change in error message is small, we use the EXPECTF matchers to make the test compatible with both old and new versions of libxml2. - Missing warnings. This is caused by a change in libxml2 where the parser started using SAX APIs internally [1]. In this case the error_type passed to php_libxml_internal_error_handler() changed from PHP_LIBXML_ERROR to PHP_LIBXML_CTX_WARNING because it internally started to use the SAX handlers instead of the generic handlers. However, for the SAX handlers the current input stack is empty, so nothing is actually printed. I fixed this by falling back to a regular warning without a filename & line number reference, which mimicks the old behaviour. Furthermore, this change now also shows an additional warning in a test which was previously hidden. [1] https://gitlab.gnome.org/GNOME/libxml2/-/commit/9a82b94a94bd310db426edd453b0f38c6c8f69f5 Closes GH-11162.
1 parent b33fbbf commit 7c0dfc5

11 files changed

+182
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ PHP NEWS
88
. Fixed bug GH-11189 (Exceeding memory limit in zend_hash_do_resize leaves
99
the array in an invalid state). (Bob)
1010

11+
- LibXML:
12+
. Fixed bug GH-11160 (Few tests failed building with new libxml 2.11.0).
13+
(nielsdos)
14+
1115
- Opcache:
1216
. Fixed bug GH-11134 (Incorrect match default branch optimization). (ilutov)
1317
. Fixed too wide OR and AND range inference. (nielsdos)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test DOMDocument::loadXML() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
6+
?>
7+
--DESCRIPTION--
8+
This test verifies the method detects attributes values not closed between " or '
9+
Environment variables used in the test:
10+
- XML_FILE: the xml file to load
11+
- LOAD_OPTIONS: the second parameter to pass to the method
12+
- EXPECTED_RESULT: the expected result
13+
--CREDITS--
14+
Antonio Diaz Ruiz <[email protected]>
15+
--INI--
16+
assert.bail=true
17+
--EXTENSIONS--
18+
dom
19+
--ENV--
20+
XML_FILE=/not_well_formed2.xml
21+
LOAD_OPTIONS=0
22+
EXPECTED_RESULT=0
23+
--FILE_EXTERNAL--
24+
domdocumentloadxml_test_method.inc
25+
--EXPECTF--
26+
Warning: DOMDocument::loadXML(): AttValue: " or ' expected in Entity, line: 4 in %s on line %d
27+
28+
Warning: DOMDocument::loadXML(): internal error: xmlParseStartTag: problem parsing attributes in Entity, line: 4 in %s on line %d
29+
30+
Warning: DOMDocument::loadXML(): Couldn't find end of Start Tag book line 4 in Entity, line: 4 in %s on line %d
31+
32+
Warning: DOMDocument::loadXML(): Opening and ending tag mismatch: books line 3 and book in Entity, line: 7 in %s on line %d
33+
34+
Warning: DOMDocument::loadXML(): Extra content at the end of the document in Entity, line: 8 in %s on line %d

ext/dom/tests/DOMDocument_loadXML_error2.phpt renamed to ext/dom/tests/DOMDocument_loadXML_error2_pre2_11.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
--TEST--
22
Test DOMDocument::loadXML() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
6+
?>
37
--DESCRIPTION--
48
This test verifies the method detects attributes values not closed between " or '
59
Environment variables used in the test:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Test DOMDocument::load() detects not-well formed
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
6+
?>
7+
--DESCRIPTION--
8+
This test verifies the method detects attributes values not closed between " or '
9+
Environment variables used in the test:
10+
- XML_FILE: the xml file to load
11+
- LOAD_OPTIONS: the second parameter to pass to the method
12+
- EXPECTED_RESULT: the expected result
13+
--CREDITS--
14+
Antonio Diaz Ruiz <[email protected]>
15+
--INI--
16+
assert.bail=true
17+
--EXTENSIONS--
18+
dom
19+
--ENV--
20+
XML_FILE=/not_well_formed2.xml
21+
LOAD_OPTIONS=0
22+
EXPECTED_RESULT=0
23+
--FILE_EXTERNAL--
24+
domdocumentload_test_method.inc
25+
--EXPECTF--
26+
Warning: DOMDocument::load(): AttValue: " or ' expected in %s on line %d
27+
28+
Warning: DOMDocument::load(): internal error: xmlParseStartTag: problem parsing attributes in %s on line %d
29+
30+
Warning: DOMDocument::load(): Couldn't find end of Start Tag book line 4 in %s on line %d
31+
32+
Warning: DOMDocument::load(): Opening and ending tag mismatch: books line 3 and book in %s on line %d
33+
34+
Warning: DOMDocument::load(): Extra content at the end of the document in %s on line %d

ext/dom/tests/DOMDocument_load_error2.phpt renamed to ext/dom/tests/DOMDocument_load_error2_pre2_11.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
--TEST--
22
Test DOMDocument::load() detects not-well formed XML
3+
--SKIPIF--
4+
<?php
5+
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
6+
?>
37
--DESCRIPTION--
48
This test verifies the method detects attributes values not closed between " or '
59
Environment variables used in the test:

ext/libxml/libxml.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,8 @@ static void php_libxml_ctx_error_level(int level, void *ctx, const char *msg)
527527
} else {
528528
php_error_docref(NULL, level, "%s in Entity, line: %d", msg, parser->input->line);
529529
}
530+
} else {
531+
php_error_docref(NULL, E_WARNING, "%s", msg);
530532
}
531533
}
532534

ext/libxml/tests/bug61367-read_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ bool(true)
5656
int(4)
5757
bool(true)
5858

59-
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
59+
Warning: DOMDocument::loadXML(): %Sfailed to load external entity "file:///%s/test_bug_61367-read/bad" in %s on line %d
6060

6161
Warning: Attempt to read property "nodeValue" on null in %s on line %d

ext/libxml/tests/libxml_disable_entity_loader_2.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ bool(true)
3939
Deprecated: Function libxml_disable_entity_loader() is deprecated in %s on line %d
4040
bool(false)
4141

42-
Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "%s" in %s on line %d
42+
Warning: DOMDocument::loadXML(): %Sfailed to load external entity "%s" in %s on line %d
4343
bool(true)
4444
Done

ext/libxml/tests/libxml_set_external_entity_loader_variation2.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ echo "Done.\n";
3939
string(10) "-//FOO/BAR"
4040
string(%d) "%sfoobar.dtd"
4141

42+
Warning: DOMDocument::validate(): Failed to load external entity "-//FOO/BAR" in %s on line %d
43+
4244
Warning: DOMDocument::validate(): Could not load the external subset "foobar.dtd" in %s on line %d
4345
bool(false)
4446
bool(true)
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
--TEST--
2+
Bug #26614 (CDATA sections skipped on line count)
3+
--EXTENSIONS--
4+
xml
5+
--SKIPIF--
6+
<?php
7+
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
8+
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
9+
?>
10+
--FILE--
11+
<?php
12+
/*
13+
this test works fine with Expat but fails with libxml
14+
which we now use as default
15+
16+
further investigation has shown that not only line count
17+
is skipped on CDATA sections but that libxml does also
18+
show different column numbers and byte positions depending
19+
on context and in opposition to what one would expect to
20+
see and what good old Expat reported just fine ...
21+
*/
22+
23+
$xmls = array();
24+
25+
// Case 1: CDATA Sections
26+
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
27+
<data>
28+
<![CDATA[
29+
multi
30+
line
31+
CDATA
32+
block
33+
]]>
34+
</data>';
35+
36+
// Case 2: replace some characters so that we get comments instead
37+
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
38+
<data>
39+
<!-- ATA[
40+
multi
41+
line
42+
CDATA
43+
block
44+
-->
45+
</data>';
46+
47+
// Case 3: replace even more characters so that only textual data is left
48+
$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
49+
<data>
50+
-!-- ATA[
51+
multi
52+
line
53+
CDATA
54+
block
55+
---
56+
</data>';
57+
58+
function startElement($parser, $name, $attrs) {
59+
printf("<$name> at line %d, col %d (byte %d)\n",
60+
xml_get_current_line_number($parser),
61+
xml_get_current_column_number($parser),
62+
xml_get_current_byte_index($parser));
63+
}
64+
65+
function endElement($parser, $name) {
66+
printf("</$name> at line %d, col %d (byte %d)\n",
67+
xml_get_current_line_number($parser),
68+
xml_get_current_column_number($parser),
69+
xml_get_current_byte_index($parser));
70+
}
71+
72+
function characterData($parser, $data) {
73+
// dummy
74+
}
75+
76+
foreach ($xmls as $desc => $xml) {
77+
echo "$desc\n";
78+
$xml_parser = xml_parser_create();
79+
xml_set_element_handler($xml_parser, "startElement", "endElement");
80+
xml_set_character_data_handler($xml_parser, "characterData");
81+
if (!xml_parse($xml_parser, $xml, true))
82+
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
83+
xml_parser_free($xml_parser);
84+
}
85+
?>
86+
--EXPECTF--
87+
CDATA
88+
<DATA> at line 2, col %d (byte 50)
89+
</DATA> at line 9, col %d (byte 96)
90+
Comment
91+
<DATA> at line 2, col %d (byte 50)
92+
</DATA> at line 9, col %d (byte 96)
93+
Text
94+
<DATA> at line 2, col %d (byte 50)
95+
</DATA> at line 9, col %d (byte 96)

ext/xml/tests/bug26614_libxml.phpt renamed to ext/xml/tests/bug26614_libxml_pre2_11.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ xml
55
--SKIPIF--
66
<?php
77
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
8+
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
89
?>
910
--FILE--
1011
<?php

0 commit comments

Comments
 (0)