mirror of
https://github.com/php/php-src.git
synced 2026-04-11 18:13:00 +02:00
We must never strip embedded whitespace; we only need to skip values when that option is set, and make sure that we keep BC regarding the different behavior for "cdata" and "complete" elements (for the former, the whole element is skipped; for the latter only the "value" key). We also fix erroneous `int` types which should actually be `size_t`. Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de> Closes GH-7493.
38 lines
844 B
PHP
38 lines
844 B
PHP
--TEST--
|
|
Bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace)
|
|
--SKIPIF--
|
|
<?php
|
|
if (!extension_loaded('xml')) die('skip xml extension not available');
|
|
?>
|
|
--FILE--
|
|
<?php
|
|
function parseAndOutput($xml)
|
|
{
|
|
$parser = xml_parser_create();
|
|
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
|
|
|
|
xml_parse_into_struct($parser, $xml, $values);
|
|
|
|
return $values;
|
|
}
|
|
|
|
$xml = "<a><b><d>\n <e></b><![CDATA[ ]]><c>\n \t</c></a>";
|
|
|
|
$parsed = parseAndOutput($xml);
|
|
|
|
// Check embedded whitespace is not getting skipped.
|
|
echo $parsed[1]['value'] . "\n";
|
|
|
|
// Check XML_OPTION_SKIP_WHITE ignores values of tags containing whitespace characters only.
|
|
var_dump(isset($parsed[2]['value']));
|
|
|
|
// Check XML_OPTION_SKIP_WHITE ignores empty <![CDATA[ ]]> values.
|
|
var_dump(count($parsed));
|
|
|
|
?>
|
|
--EXPECT--
|
|
<d>
|
|
<e>
|
|
bool(false)
|
|
int(4)
|