summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--it_xml.class2
-rwxr-xr-xtests/it_xml.t18
2 files changed, 14 insertions, 6 deletions
diff --git a/it_xml.class b/it_xml.class
index 6013b52..ff594fd 100644
--- a/it_xml.class
+++ b/it_xml.class
@@ -89,7 +89,7 @@ function from_xml($xmldata, $p)
$xmldata = '<?xml version="1.0" encoding="' . $this->_p['encoding'] . '"?>' . $xmldata;
# decode illegal entities but protect semantically important ones
- $xmldata = html_entity_decode(preg_replace('/&(amp|lt|gt|#38|#60|#62|#x26|#x3C|#3E);/i', '&amp;$1;', $xmldata));
+ $xmldata = html_entity_decode(preg_replace('/&(amp|lt|gt|#38|#60|#62|#x26|#x3C|#x3E);/i', '&amp;$1;', $xmldata), ENT_QUOTES, $this->_p['encoding']);
$result = xml_parse($parser, $xmldata);
}
diff --git a/tests/it_xml.t b/tests/it_xml.t
index a0922c5..8c2c084 100755
--- a/tests/it_xml.t
+++ b/tests/it_xml.t
@@ -3,11 +3,11 @@
# Tests for xml.class
-function match($xmldata, $expected, $name, $prefix = "")
+function match($xmldata, $expected, $name, $prefix = "", $p = array())
{
$classname = $prefix ? ($prefix . "_xml") : "it_xml";
$varname = $prefix . "foo";
- $xml = new $classname("<root>$xmldata</root>");
+ $xml = new $classname("<root>$xmldata</root>", $p);
is(
preg_replace('/[#\s]+/', " ", print_r($xml->$varname, true)),
@@ -47,9 +47,17 @@ match(
);
match(
- '<foo>&amp;&lt;&gt;&#38;&#60;&#62;&#x26;&#x3C;&#x3E; &uuml;</foo>',
- 'foo Object ( [val] => &<>&<>&<> ü ) ',
- 'Predecode illegal entities',
+ '<foo>&amp;amp; &lt;a&gt; &#38;amp; &#60;b&#62; &#x26;amp; &#x3C;c&#x3E; &uuml;</foo>',
+ 'foo Object ( [val] => &amp; <a> &amp; <b> &amp; <c> ü ) ',
+ 'Predecode illegal entities while keeping properly encoded ones',
+);
+
+match(
+ '<foo>&amp;amp; &lt;a&gt; &#38;amp; &#60;b&#62; &#x26;amp; &#x3C;c&#x3E; &uuml;</foo>',
+ utf8_encode('foo Object ( [val] => &amp; <a> &amp; <b> &amp; <c> ü ) '),
+ 'Predecode illegal entities while keeping properly encoded ones (UTF-8)',
+ "",
+ array('encoding' => "UTF-8"),
);