ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r955226 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/util/DOMElementWriter.java src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
Date Wed, 16 Jun 2010 13:42:39 GMT
Author: bodewig
Date: Wed Jun 16 13:42:39 2010
New Revision: 955226

URL: http://svn.apache.org/viewvc?rev=955226&view=rev
Log:
use a better approach to encode CDATA end markers in CDATA sections as suggested by Mark Lassau
and Wikipedia.  PR 49404

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=955226&r1=955225&r2=955226&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Wed Jun 16 13:42:39 2010
@@ -20,6 +20,9 @@ Changes that could break older environme
    ampersands so that { remained { rather than being turned
    into {.  This is no longer the case, ampersands will now
    be encoded unconditionally.
+   Also DOMElementWriter#encodeData will treat CDATA sections containing a
+   literal "]]>" sequence different now - it will split the CDATA
+   section between the second "]" and ">" and create two sections.
    This affects <echoxml> task as well as the XML logger or JUnit
    formatter where ampersands will now always get encoded.
    Bugzilla Report 49404.

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java?rev=955226&r1=955225&r2=955226&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java Wed Jun 16 13:42:39
2010
@@ -467,19 +467,7 @@ public class DOMElementWriter {
             }
         }
 
-        String result = sb.substring(0);
-        int cdEnd = result.indexOf("]]>");
-        while (cdEnd != -1) {
-            sb.setLength(cdEnd);
-            // CheckStyle:MagicNumber OFF
-            sb.append("&#x5d;&#x5d;&gt;")
-                .append(result.substring(cdEnd + 3));
-            // CheckStyle:MagicNumber ON
-            result = sb.substring(0);
-            cdEnd = result.indexOf("]]>");
-        }
-
-        return result;
+        return sb.toString().replace("]]>", "]]]]><![CDATA[>");
     }
 
     /**

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java?rev=955226&r1=955225&r2=955226&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java Wed
Jun 16 13:42:39 2010
@@ -90,11 +90,11 @@ public class DOMElementWriterTest extend
     public void testCDATAEndEncoding() {
         assertEquals("]>", w.encodedata("]>"));
         assertEquals("]]", w.encodedata("]]"));
-        assertEquals("&#x5d;&#x5d;&gt;", w.encodedata("]]>"));
-        assertEquals("&#x5d;&#x5d;&gt;A", w.encodedata("]]>A"));
-        assertEquals("A&#x5d;&#x5d;&gt;", w.encodedata("A]]>"));
-        assertEquals("A&#x5d;&#x5d;&gt;A", w.encodedata("A]]>A"));
-        assertEquals("A&#x5d;&#x5d;&gt;B&#x5d;&#x5d;&gt;C",
+        assertEquals("]]]]><![CDATA[>", w.encodedata("]]>"));
+        assertEquals("]]]]><![CDATA[>A", w.encodedata("]]>A"));
+        assertEquals("A]]]]><![CDATA[>", w.encodedata("A]]>"));
+        assertEquals("A]]]]><![CDATA[>A", w.encodedata("A]]>A"));
+        assertEquals("A]]]]><![CDATA[>B]]]]><![CDATA[>C",
                      w.encodedata("A]]>B]]>C"));
     }
 



Mime
View raw message