Skip to content

Commit

Permalink
Fix error when generating Xml.
Browse files Browse the repository at this point in the history
Fix warnings/un-escaped entities with deeply nested elements.

Fixes #3718
  • Loading branch information
markstory committed Mar 22, 2013
1 parent 819029e commit 5d6a6fa
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Utility/XmlTest.php
Expand Up @@ -459,6 +459,41 @@ public function testFromArrayFail($value) {
}
}

/**
* Test that there are not unterminated errors when building xml
*
* @return void
*/
public function testFromArrayUnterminatedError() {
$data = array(
'product_ID' => 'GENERT-DL',
'deeplink' => 'http://example.com/deep',
'image_URL' => 'http://example.com/image',
'thumbnail_image_URL' => 'http://example.com/thumb',
'brand' => 'Malte Lange & Co',
'availability' => 'in stock',
'authors' =>array(
'author' => array('Malte Lange & Co')
)
);
$xml = Xml::fromArray(array('products' => $data), 'tags');
$expected = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<products>
<product_ID>GENERT-DL</product_ID>
<deeplink>http://example.com/deep</deeplink>
<image_URL>http://example.com/image</image_URL>
<thumbnail_image_URL>http://example.com/thumb</thumbnail_image_URL>
<brand>Malte Lange &amp; Co</brand>
<availability>in stock</availability>
<authors>
<author>Malte Lange &amp; Co</author>
</authors>
</products>
XML;
$this->assertXmlStringEqualsXmlString($expected, $xml->asXML());
}

/**
* testToArray method
*
Expand Down
5 changes: 2 additions & 3 deletions lib/Cake/Utility/Xml.php
Expand Up @@ -300,10 +300,9 @@ protected static function _createChild($data) {
$childValue = (string)$value;
}

$child = $dom->createElement($key);
if ($childValue) {
$child = $dom->createElement($key, $childValue);
} else {
$child = $dom->createElement($key);
$child->appendChild($dom->createTextNode($childValue));
}
if ($childNS) {
$child->setAttribute('xmlns', $childNS);
Expand Down

0 comments on commit 5d6a6fa

Please sign in to comment.