mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-07 20:12:42 +00:00
Fixes #6318: Incorrect whitespace handling/parsing of XML documents
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8158 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
c8cf1a2c5b
commit
9f15226e46
2 changed files with 26 additions and 1 deletions
|
@ -880,10 +880,11 @@ class Xml extends XmlNode {
|
|||
*/
|
||||
function parse() {
|
||||
$this->__initParser();
|
||||
$this->__rawData = trim($this->__rawData);
|
||||
$this->__header = trim(str_replace(
|
||||
a('<' . '?', '?' . '>'),
|
||||
a('', ''),
|
||||
substr(trim($this->__rawData), 0, strpos($this->__rawData, "\n"))
|
||||
substr($this->__rawData, 0, strpos($this->__rawData, '?' . '>'))
|
||||
));
|
||||
|
||||
xml_parse_into_struct($this->__parser, $this->__rawData, $vals);
|
||||
|
|
|
@ -389,6 +389,30 @@ class XmlTest extends CakeTestCase {
|
|||
$result = $node->removeAttribute('missing');
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that XML documents with non-standard spacing (i.e. leading whitespace, whole document
|
||||
* on one line) still parse properly.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testParsingWithNonStandardWhitespace() {
|
||||
$raw = '<?xml version="1.0" encoding="ISO-8859-1" ?><prices><price>1.0</price></prices>';
|
||||
$array = array('Prices' => array('price' => 1.0));
|
||||
|
||||
$xml = new Xml($raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
|
||||
$xml = new Xml(' ' . $raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
|
||||
$xml = new Xml("\n" . $raw);
|
||||
$this->assertEqual($xml->toArray(), $array);
|
||||
$this->assertEqual($xml->__header, 'xml version="1.0" encoding="ISO-8859-1"');
|
||||
}
|
||||
|
||||
/* Not implemented yet */
|
||||
/* function testChildFilter() {
|
||||
$input = array(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue