Permalink
Browse files

Workaround for a PHP/libxml-bug with entities

As described on http://bugs.php.net/bug.php?idE996, current versions of libxml (2.7.0/1) lead to the fact that the xml parser of PHP eats predefined entities. As proposed on http://bugs.simplepie.org/issues/show/101 predefined entities are replaced by their numeric equivalents. There is no condition in this patch as there are people reporting it isn't gone in 2.7.2, i can confirm that, and furthermore here PHP is reporting libxml 20632 and the bug exists, too (it is linked to libxml2 though which has version 2.7.2). As soon as there is definite knowledge on which versions are actually concerned and how to detect them in PHP a condition should be added as this patch might decrease the performance of the affected functions.

darcs-hash:20081229213341-074e0-10e0cca836c6599efe4d3dfd45f512d624d0a808.gz
  • Loading branch information...
1 parent 8ace412 commit 8285d596bc77e829954be44ccfe8958b1d0387ae @michitux michitux committed Dec 29, 2008
Showing with 13 additions and 0 deletions.
  1. +6 −0 inc/IXR_Library.php
  2. +7 −0 inc/SimplePie.php
View
@@ -144,6 +144,12 @@ function IXR_Message ($message) {
function parse() {
// first remove the XML declaration
$this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message);
+ // workaround for a bug in PHP/libxml2, see http://bugs.php.net/bug.php?id=45996
+ $this->message = str_replace('&lt;', '&#60;', $this->message);
+ $this->message = str_replace('&gt;', '&#62;', $this->message);
+ $this->message = str_replace('&amp;', '&#38;', $this->message);
+ $this->message = str_replace('&apos;', '&#39;', $this->message);
+ $this->message = str_replace('&quot;', '&#34;', $this->message);
if (trim($this->message) == '') {
return false;
}
View
@@ -10297,6 +10297,13 @@ function parse(&$data)
xml_set_character_data_handler($this->xml, 'cdata');
xml_set_element_handler($this->xml, 'tag_open', 'tag_close');
+ // workound for a bug in PHP/libxml2 as described on http://bugs.simplepie.org/issues/show/101
+ $data = str_replace('&lt;', '&#60;', $data);
+ $data = str_replace('&gt;', '&#62;', $data);
+ $data = str_replace('&amp;', '&#38;', $data);
+ $data = str_replace('&apos;', '&#39;', $data);
+ $data = str_replace('&quot;', '&#34;', $data);
+
// Parse!
if (!xml_parse($this->xml, $data, true))
{

0 comments on commit 8285d59

Please sign in to comment.