Skip to content

Fix GH-13517: Multiple test failures when building with --with-expat #13522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions ext/reflection/tests/016.phpt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
9 changes: 9 additions & 0 deletions ext/xml/tests/libxml_expat_skipif.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
function skipif(bool $want_expat) {
ob_start();
echo phpinfo(INFO_MODULES);
$output = ob_get_clean();
if ($want_expat !== str_contains($output, 'EXPAT')) {
die('skip test is for ' . ($want_expat ? 'Expat' : 'libxml'));
}
}
Loading