Skip to content

Commit

Permalink
Fix GH-13517: Multiple test failures when building with --with-expat
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nielsdos committed Feb 27, 2024
1 parent b4e272c commit 552ea62
Show file tree
Hide file tree
Showing 15 changed files with 209 additions and 267 deletions.
3 changes: 3 additions & 0 deletions NEWS
Expand Up @@ -5,6 +5,9 @@ PHP NEWS
- PDO:
. Fix various PDORow bugs. (Girgias)

- XML:
. Fixed bug GH-13517 (Multiple test failures when building with
--with-expat). (nielsdos)

14 Mar 2024, PHP 8.2.17

Expand Down
8 changes: 5 additions & 3 deletions ext/reflection/tests/016.phpt
@@ -1,15 +1,17 @@
--TEST--
ReflectionExtension::getDependencies()
--EXTENSIONS--
xml
dom
--FILE--
<?php
$ext = new ReflectionExtension("xml");
$ext = new ReflectionExtension("dom");
$deps = $ext->getDependencies();
var_dump($deps);
?>
--EXPECT--
array(1) {
array(2) {
["libxml"]=>
string(8) "Required"
["domxml"]=>
string(9) "Conflicts"
}
73 changes: 73 additions & 0 deletions ext/xml/tests/bug26614.inc
@@ -0,0 +1,73 @@
<?php
/*
this test has different output on libxml2 (even depending on the version) and Expat
further investigation has shown that not only line count
is skippet on CDATA sections but that libxml does also
show different column numbers and byte positions depending
on context and in opposition to what one would expect to
see and what good old Expat reported just fine ...
*/

$xmls = array();

// Case 1: CDATA Sections
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<![CDATA[
multi
line
CDATA
block
]]>
</data>';

// Case 2: replace some characters so that we get comments instead
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<!-- ATA[
multi
line
CDATA
block
-->
</data>';

// Case 3: replace even more characters so that only textual data is left
$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
-!-- ATA[
multi
line
CDATA
block
---
</data>';

function startElement($parser, $name, $attrs) {
printf("<$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function endElement($parser, $name) {
printf("</$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function characterData($parser, $data) {
// dummy
}

foreach ($xmls as $desc => $xml) {
echo "$desc\n";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $xml, true))
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
xml_parser_free($xml_parser);
}
83 changes: 6 additions & 77 deletions ext/xml/tests/bug26614.phpt
Expand Up @@ -4,91 +4,20 @@ Bug #26614 (CDATA sections skipped on line count)
xml
--SKIPIF--
<?php
if (defined("LIBXML_VERSION")) die('skip expat test');
require __DIR__ . '/libxml_expat_skipif.inc';
skipif(want_expat: true);
?>
--FILE--
<?php
/*
this test works fine with Expat but fails with libxml
which we now use as default
further investigation has shown that not only line count
is skippet on CDATA sections but that libxml does also
show different column numbers and byte positions depending
on context and in opposition to what one would expect to
see and what good old Expat reported just fine ...
*/

$xmls = array();

// Case 1: CDATA Sections
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<![CDATA[
multi
line
CDATA
block
]]>
</data>';

// Case 2: replace some characters so that we get comments instead
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<!-- ATA[
multi
line
CDATA
block
-->
</data>';

// Case 3: replace even more characters so that only textual data is left
$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
-!-- ATA[
multi
line
CDATA
block
---
</data>';

function startElement($parser, $name, $attrs) {
printf("<$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function endElement($parser, $name) {
printf("</$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function characterData($parser, $data) {
// dummy
}

foreach ($xmls as $desc => $xml) {
echo "$desc\n";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $xml, true))
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
xml_parser_free($xml_parser);
}
require __DIR__ . '/bug26614.inc';
?>
--EXPECT--
CDATA
<DATA> at line 2, col 0 (byte 45)
</DATA> at line 9, col 0 (byte 90)
</DATA> at line 9, col 0 (byte 89)
Comment
<DATA> at line 2, col 0 (byte 45)
</DATA> at line 9, col 0 (byte 90)
</DATA> at line 9, col 0 (byte 89)
Text
<DATA> at line 2, col 0 (byte 45)
</DATA> at line 9, col 0 (byte 90)
</DATA> at line 9, col 0 (byte 89)
77 changes: 3 additions & 74 deletions ext/xml/tests/bug26614_libxml_gte2_11.phpt
Expand Up @@ -4,84 +4,13 @@ Bug #26614 (CDATA sections skipped on line count)
xml
--SKIPIF--
<?php
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
require __DIR__ . '/libxml_expat_skipif.inc';
skipif(want_expat: false);
if (LIBXML_VERSION < 21100) die('skip libxml2 test variant for version >= 2.11');
?>
--FILE--
<?php
/*
this test works fine with Expat but fails with libxml
which we now use as default
further investigation has shown that not only line count
is skipped on CDATA sections but that libxml does also
show different column numbers and byte positions depending
on context and in opposition to what one would expect to
see and what good old Expat reported just fine ...
*/

$xmls = array();

// Case 1: CDATA Sections
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<![CDATA[
multi
line
CDATA
block
]]>
</data>';

// Case 2: replace some characters so that we get comments instead
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<!-- ATA[
multi
line
CDATA
block
-->
</data>';

// Case 3: replace even more characters so that only textual data is left
$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
-!-- ATA[
multi
line
CDATA
block
---
</data>';

function startElement($parser, $name, $attrs) {
printf("<$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function endElement($parser, $name) {
printf("</$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function characterData($parser, $data) {
// dummy
}

foreach ($xmls as $desc => $xml) {
echo "$desc\n";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $xml, true))
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
xml_parser_free($xml_parser);
}
require __DIR__ . '/bug26614.inc';
?>
--EXPECTF--
CDATA
Expand Down
77 changes: 3 additions & 74 deletions ext/xml/tests/bug26614_libxml_pre2_11.phpt
Expand Up @@ -4,84 +4,13 @@ Bug #26614 (CDATA sections skipped on line count)
xml
--SKIPIF--
<?php
if (!defined("LIBXML_VERSION")) die('skip libxml2 test');
require __DIR__ . '/libxml_expat_skipif.inc';
skipif(want_expat: false);
if (LIBXML_VERSION >= 21100) die('skip libxml2 test variant for version < 2.11');
?>
--FILE--
<?php
/*
this test works fine with Expat but fails with libxml
which we now use as default
further investigation has shown that not only line count
is skipped on CDATA sections but that libxml does also
show different column numbers and byte positions depending
on context and in opposition to what one would expect to
see and what good old Expat reported just fine ...
*/

$xmls = array();

// Case 1: CDATA Sections
$xmls["CDATA"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<![CDATA[
multi
line
CDATA
block
]]>
</data>';

// Case 2: replace some characters so that we get comments instead
$xmls["Comment"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
<!-- ATA[
multi
line
CDATA
block
-->
</data>';

// Case 3: replace even more characters so that only textual data is left
$xmls["Text"] ='<?xml version="1.0" encoding="iso-8859-1" ?>
<data>
-!-- ATA[
multi
line
CDATA
block
---
</data>';

function startElement($parser, $name, $attrs) {
printf("<$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function endElement($parser, $name) {
printf("</$name> at line %d, col %d (byte %d)\n",
xml_get_current_line_number($parser),
xml_get_current_column_number($parser),
xml_get_current_byte_index($parser));
}

function characterData($parser, $data) {
// dummy
}

foreach ($xmls as $desc => $xml) {
echo "$desc\n";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!xml_parse($xml_parser, $xml, true))
echo "Error: ".xml_error_string(xml_get_error_code($xml_parser))."\n";
xml_parser_free($xml_parser);
}
require __DIR__ . '/bug26614.inc';
?>
--EXPECTF--
CDATA
Expand Down
4 changes: 2 additions & 2 deletions ext/xml/tests/bug46699.phpt
Expand Up @@ -27,8 +27,8 @@ xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parse($parser, $xml);
xml_parser_free($parser);
?>
--EXPECT--
<a xmlns="http://example.com/foo" xmlns:bar="http://example.com/bar">
--EXPECTF--
<a xmlns="http://example.com/foo"%axmlns:bar="http://example.com/bar">
<bar:b foo="bar">1</bar:b>
<bar:c bar:nix="null" foo="bar">2</bar:c>
</a>
4 changes: 2 additions & 2 deletions ext/xml/tests/bug81351.phpt
Expand Up @@ -22,5 +22,5 @@ $error = xml_error_string($code);
echo "xml_parse returned $success, xml_get_error_code = $code, xml_error_string = $error\r\n";
?>
--EXPECTF--
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = No error
%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
xml_parse returned 1, xml_get_error_code = 0, xml_error_string = %S
%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 comments on commit 552ea62

Please sign in to comment.