From 8285d596bc77e829954be44ccfe8958b1d0387ae Mon Sep 17 00:00:00 2001
From: michael <michael@content-space.de>
Date: Mon, 29 Dec 2008 22:33:41 +0100
Subject: [PATCH] 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
---
 inc/IXR_Library.php | 6 ++++++
 inc/SimplePie.php   | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php
index fb11585ca..ae77f2c27 100644
--- a/inc/IXR_Library.php
+++ b/inc/IXR_Library.php
@@ -144,6 +144,12 @@ class IXR_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;
         }
diff --git a/inc/SimplePie.php b/inc/SimplePie.php
index 390b7e0a0..b5dab727f 100644
--- a/inc/SimplePie.php
+++ b/inc/SimplePie.php
@@ -10297,6 +10297,13 @@ class SimplePie_Parser
 		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))
 		{
-- 
GitLab