Bug #70962 [Opn->Ver]: xml_parse_into_struct strips embedded whitespace with XML_OPTION_SKIP_WHITE
| From: | cmb@php.net | Date: | Mon, 08 Oct 2018 15:16:42 +0000 |
| Subject: | Bug #70962 [Opn->Ver]: xml_parse_into_struct strips embedded whitespace with XML_OPTION_SKIP_WHITE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-217473@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70962&edit=1
ID: 70962
Updated by: cmb@php.net
Reported by: dwilks at intacct dot com
Summary: xml_parse_into_struct strips embedded whitespace
with XML_OPTION_SKIP_WHITE
-Status: Open
+Status: Verified
Type: Bug
Package: *XML functions
Operating System: OSX 10.9.4
PHP Version: 7.0.0RC7
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Although, the documentation on XML_OPTION_SKIP_WHITE is not
particularly clear, since it doesn't mention that this option is
only relevant for xml_parse_into_struct(), and only there âvalueâ
has a clearly defined meaning, this is clearly a bug. It is
particularly strange, that this whitespace removal depends on the
kind of whitespace, if ext/xml is built against libexpat, in which
case the first parseAndOutput() removes the LF, but would not
remove a space.
Previous Comments:
------------------------------------------------------------------------
[2015-11-24 01:25:27] dwilks at intacct dot com
Description:
------------
XML_OPTION_SKIP_WHITE should skip elements if the entire element is whitespace. Unfortunately it
looks like expat calls the character handler on individual xml entities within a string so any
whitespace between xml entities is ignored.
Looks like the hhvm guys noticed and "fixed this"
Test script:
---------------
@ https://3v4l.org/4TD9v also
<?php
function handleCharacterData($parser, $data)
{
echo __FUNCTION__ . " - " . $data . "\n";
}
function handleElementStart($parser, $name, $attributes)
{
echo __FUNCTION__ . " - " . $name . "\n";
}
function handleElementEnd($parser, $name)
{
echo __FUNCTION__ . " - " . $name . "\n";
}
function parseAndOutput($s)
{
$p = xml_parser_create();
xml_parser_set_option($p, XML_OPTION_SKIP_WHITE, 1);
xml_set_character_data_handler($p, 'handleCharacterData');
xml_set_element_handler($p, 'handleElementStart', 'handleElementEnd');
xml_parse_into_struct($p, $s, $values);
echo $values[0]['value'] . "\n\n";
}
$s = "<a>b\nc</a>";
parseAndOutput($s);
$s = "<a><b>\n<c></a>";
parseAndOutput($s);
Expected result:
----------------
handleElementStart - A
handleCharacterData - b
c
handleElementEnd - A
b
c
handleElementStart - A
handleCharacterData - <b>
<c>
handleElementEnd - A
<b>
<c>
Actual result:
--------------
handleElementStart - A
handleCharacterData - b
c
handleElementEnd - A
b
c
handleElementStart - A
handleCharacterData - <
handleCharacterData - b
handleCharacterData - >
handleCharacterData -
handleCharacterData - <
handleCharacterData - c
handleCharacterData - >
handleElementEnd - A
<b><c>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70962&edit=1