Bug #70962 [NEW]: xml_parse_into_struct strips embedded whitespace with XML_OPTION_SKIP_WHITE
| From: | dwilks at intacct dot com | Date: | Tue, 24 Nov 2015 01:25:29 +0000 |
| Subject: | Bug #70962 [NEW]: xml_parse_into_struct strips embedded whitespace with XML_OPTION_SKIP_WHITE | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-197385@lists.php.net to get a copy of this message | ||
From: dwilks at intacct dot com
Operating system: OSX 10.9.4
PHP version: 7.0.0RC7
Package: *XML functions
Bug Type: Bug
Bug description:xml_parse_into_struct strips embedded whitespace with XML_OPTION_SKIP_WHITE
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 bug report at https://bugs.php.net/bug.php?id=70962&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=70962&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=70962&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=70962&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=70962&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=70962&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=70962&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=70962&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=70962&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=70962&r=support
Expected behavior: https://bugs.php.net/fix.php?id=70962&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=70962&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=70962&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=70962&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70962&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=70962&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=70962&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=70962&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70962&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=70962&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=70962&r=mysqlcfg