Skip to content

Commit 552ea62

Browse files
committed
Fix GH-13517: Multiple test failures when building with --with-expat
The reflection failure is because the XML extension is used to check the module dependency information, but that extension can be configured to not depend on ext/libxml, resulting in a different output. The solution is to check another extension instead. The test failures in ext/xml/tests are because of different behaviour between libxml2 and Expat error handling. These are expected differences and the solution is to split the tests. Closes GH-13522.
1 parent b4e272c commit 552ea62

15 files changed

+209
-267
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ PHP NEWS
55
- PDO:
66
. Fix various PDORow bugs. (Girgias)
77

8+
- XML:
9+
. Fixed bug GH-13517 (Multiple test failures when building with
10+
--with-expat). (nielsdos)
811

912
14 Mar 2024, PHP 8.2.17
1013

ext/reflection/tests/016.phpt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
--TEST--
22
ReflectionExtension::getDependencies()
33
--EXTENSIONS--
4-
xml
4+
dom
55
--FILE--
66
<?php
7-
$ext = new ReflectionExtension("xml");
7+
$ext = new ReflectionExtension("dom");
88
$deps = $ext->getDependencies();
99
var_dump($deps);
1010
?>
1111
--EXPECT--
12-
array(1) {
12+
array(2) {
1313
["libxml"]=>
1414
string(8) "Required"
15+
["domxml"]=>
16+
string(9) "Conflicts"
1517
}

ext/xml/tests/bug26614.inc

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/*
3+
this test has different output on libxml2 (even depending on the version) and Expat
4+
5+
further investigation has shown that not only line count
6+
is skippet on CDATA sections but that libxml does also
7+
show different column numbers and byte positions depending
8+
on context and in opposition to what one would expect to
9+
see and what good old Expat reported just fine ...
10+
*/
11+
12+
$xmls = array();
13+
14+
// Case 1: CDATA Sections
15+
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
16+
<data>
17+
<![CDATA[
18+
multi
19+
line
20+
CDATA
21+
block
22+
]]>
23+
</data>';
24+
25+
// Case 2: replace some characters so that we get comments instead
26+
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
27+
<data>
28+
<!-- ATA[
29+
multi
30+
line
31+
CDATA
32+
block
33+
-->
34+
</data>';
35+
36+
// Case 3: replace even more characters so that only textual data is left
37+
$xmls["Text"] ='<?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+
function startElement($parser, $name, $attrs) {
48+
printf("<$name> at line %d, col %d (byte %d)\n",
49+
xml_get_current_line_number($parser),
50+
xml_get_current_column_number($parser),
51+
xml_get_current_byte_index($parser));
52+
}
53+
54+
function endElement($parser, $name) {
55+
printf("</$name> at line %d, col %d (byte %d)\n",
56+
xml_get_current_line_number($parser),
57+
xml_get_current_column_number($parser),
58+
xml_get_current_byte_index($parser));
59+
}
60+
61+
function characterData($parser, $data) {
62+
// dummy
63+
}
64+
65+
foreach ($xmls as $desc => $xml) {
66+
echo "$desc\n";
67+
$xml_parser = xml_parser_create();
68+
xml_set_element_handler($xml_parser, "startElement", "endElement");
69+
xml_set_character_data_handler($xml_parser, "characterData");
70+
if (!xml_parse($xml_parser, $xml, true))
71+
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
72+
xml_parser_free($xml_parser);
73+
}

ext/xml/tests/bug26614.phpt

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

ext/xml/tests/bug26614_libxml_gte2_11.phpt

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,13 @@ Bug #26614 (CDATA sections skipped on line count)
44
xml
55
--SKIPIF--
66
<?php
7-
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
7+
require __DIR__ . '/libxml_expat_skipif.inc';
8+
skipif(want_expat: false);
89
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
910
?>
1011
--FILE--
1112
<?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-
}
13+
require __DIR__ . '/bug26614.inc';
8514
?>
8615
--EXPECTF--
8716
CDATA

ext/xml/tests/bug26614_libxml_pre2_11.phpt

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,84 +4,13 @@ Bug #26614 (CDATA sections skipped on line count)
44
xml
55
--SKIPIF--
66
<?php
7-
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
7+
require __DIR__ . '/libxml_expat_skipif.inc';
8+
skipif(want_expat: false);
89
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
910
?>
1011
--FILE--
1112
<?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-
}
13+
require __DIR__ . '/bug26614.inc';
8514
?>
8615
--EXPECTF--
8716
CDATA

ext/xml/tests/bug46699.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
2727
xml_parse($parser, $xml);
2828
xml_parser_free($parser);
2929
?>
30-
--EXPECT--
31-
<a xmlns="http://example.com/foo" xmlns:bar="http://example.com/bar">
30+
--EXPECTF--
31+
<a xmlns="http://example.com/foo"%axmlns:bar="http://example.com/bar">
3232
<bar:b foo="bar">1</bar:b>
3333
<bar:c bar:nix="null" foo="bar">2</bar:c>
3434
</a>

ext/xml/tests/bug81351.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ $error = xml_error_string($code);
2222
echo "xml_parse returned $success, xml_get_error_code = $code, xml_error_string = $error\r\n";
2323
?>
2424
--EXPECTF--
25-
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = No error
26-
%rxml_parse returned 0, xml_get_error_code = 5, xml_error_string = Invalid document end|xml_parse returned 0, xml_get_error_code = 77, xml_error_string = Tag not finished%r
25+
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = %S
26+
%rxml_parse returned 0, xml_get_error_code = 5, xml_error_string = Invalid document end|xml_parse returned 0, xml_get_error_code = 3, xml_error_string = no element found|xml_parse returned 0, xml_get_error_code = 77, xml_error_string = Tag not finished%r

0 commit comments

Comments
 (0)