xref: /PHP-8.0/ext/xml/tests/bug70962.phpt (revision a9661a52)
1--TEST--
2Bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace)
3--SKIPIF--
4<?php
5if (!extension_loaded('xml')) die('skip xml extension not available');
6?>
7--FILE--
8<?php
9function parseAndOutput($xml)
10{
11    $parser = xml_parser_create();
12    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
13
14    xml_parse_into_struct($parser, $xml, $values);
15
16    return $values;
17}
18
19$xml = "<a><b>&lt;d&gt;\n &lt;e&gt;</b><![CDATA[  ]]><c>\n \t</c></a>";
20
21$parsed = parseAndOutput($xml);
22
23// Check embedded whitespace is not getting skipped.
24echo $parsed[1]['value'] . "\n";
25
26// Check XML_OPTION_SKIP_WHITE ignores values of tags containing whitespace characters only.
27var_dump(isset($parsed[2]['value']));
28
29// Check XML_OPTION_SKIP_WHITE ignores empty <![CDATA[  ]]> values.
30var_dump(count($parsed));
31
32?>
33--EXPECT--
34<d>
35 <e>
36bool(false)
37int(4)
38