From ab3cf47553064614811744381f1cf455f3e9184d Mon Sep 17 00:00:00 2001
From: Peter Philipp <peter.philipp@cando-image.com>
Date: Tue, 8 Nov 2011 21:37:58 +0100
Subject: [PATCH] Issue #998590 by Charles51, das-peter, pisco: Prevent double
 CDATA section escaping in
 filter_dom_serialize_escape_cdata_element() to avoid
 warnings

---
 core/modules/filter/filter.test |   53 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/core/modules/filter/filter.test b/core/modules/filter/filter.test
index 67d0833..df241cd 100644
--- a/core/modules/filter/filter.test
+++ b/core/modules/filter/filter.test
@@ -1637,6 +1637,59 @@ alert("test")
  /* Styling */ body {color:red}
 /*--><!]]>*/
 </style></p>', t('HTML corrector -- CDATA added to a style element.'));
+
+    // Check if doubling cdata escaping is prevented.
+    $cdata_patterns = array(
+      '<!--//--><![CDATA[// ><!-- ' => <<<EOT
+<p><script type="text/javascript">
+  <!--//--><![CDATA[// ><!--
+    alert("test");
+  //--><!]]>
+</script></p>
+EOT
+,
+      '// <![CDATA[' => <<<EOT
+<p><script type="text/javascript">
+  // <![CDATA[
+    alert("test");
+  // ]]>
+</script></p>',
+EOT
+,
+      '//<![CDATA[' => <<<EOT
+<p><script type="text/javascript">
+  //<![CDATA[
+    alert("test");
+  //]]>
+</script></p>'
+EOT
+,
+      '<!--/*--><![CDATA[/* ><!--*/' => <<<EOT
+<p><style>
+  <!--/*--><![CDATA[/* ><!--*/
+  /* Styling */
+  body {color:red}
+  /*--><!]]>*/
+</style></p>'
+EOT
+,
+      '/*<![CDATA[*/' => <<<EOT
+<p><style>
+  /*<![CDATA[*/
+  /* Styling */
+  body {color:red}
+  /*]]>*/
+</style></p>'
+EOT
+,
+    );
+    foreach ($cdata_patterns as $pattern_name => $pattern_data) {
+      $filtered_data = _filter_htmlcorrector($pattern_data);
+      $this->assertTrue(
+        (strstr($filtered_data, ']]]]><![CDATA[>') !== FALSE),
+        t('HTML corrector -- Existing cdata section @pattern_name properly escaped', array('@pattern_name' => $pattern_name))
+      );
+    }
   }
 
   /**
-- 
1.7.7.msysgit.1

