bodewig 2003/01/15 06:02:49 Modified: . WHATSNEW src/main/org/apache/tools/ant/util DOMElementWriter.java src/testcases/org/apache/tools/ant/util DOMElementWriterTest.java Log: Don't allow ]]> within CDATA sections. Revision Changes Path 1.340 +2 -2 jakarta-ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/jakarta-ant/WHATSNEW,v retrieving revision 1.339 retrieving revision 1.340 diff -u -r1.339 -r1.340 --- WHATSNEW 14 Jan 2003 18:39:55 -0000 1.339 +++ WHATSNEW 15 Jan 2003 14:02:49 -0000 1.340 @@ -17,6 +17,8 @@ * The <script> task now requires Apache BSF instead of the older IBM version. See <http://jakarta.apache.org/bsf/> +* <xmlproperty> will no longer fail if the file to be loaded doesn't exist. + Fixed bugs: ----------- * <translate> was not ignoring comment lines. @@ -167,8 +169,6 @@ * <classfileset> now picks up dependencies of the form MyClass.class. This works for the code generated by the Sun java compiler. It may not work for all compilers. - -* <xmlproperty> will no longer fail if the file to be loaded doesn't exist. Changes from Ant 1.5.1Beta1 to 1.5.1 ==================================== 1.13 +21 -3 jakarta-ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java Index: DOMElementWriter.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v retrieving revision 1.12 retrieving revision 1.13 diff -u -r1.12 -r1.13 --- DOMElementWriter.java 25 Jul 2002 15:21:24 -0000 1.12 +++ DOMElementWriter.java 15 Jan 2003 14:02:49 -0000 1.13 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -242,8 +242,15 @@ /** * Drop characters that are illegal in XML documents. * + * <p>Also ensure that we are not including an <code>]]></code> + * marker by replacing that sequence with + * <code>&x5d;&x5d;&gt;</code>.</p> + * * <p>See XML 1.0 2.2 <a - * href="http://www.w3.org/TR/1998/REC-xml-19980210#charsets">http://www.w3.org/TR/1998/REC-xml-19980210#charsets</a>.</p> + * href="http://www.w3.org/TR/1998/REC-xml-19980210#charsets">http://www.w3.org/TR/1998/REC-xml-19980210#charsets</a>. and + * 2.7 <a + * href="http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect">http://www.w3.org/TR/1998/REC-xml-19980210#sec-cdata-sect</a></p> + */ public String encodedata(final String value) { sb.setLength(0); @@ -253,7 +260,18 @@ sb.append(c); } } - return sb.toString(); + + String result = sb.toString(); + int cdEnd = result.indexOf("]]>"); + while (cdEnd != -1) { + sb.setLength(cdEnd); + sb.append("&x5d;&x5d;>") + .append(result.substring(cdEnd+3)); + result = sb.toString(); + cdEnd = result.indexOf("]]>"); + } + + return result; } /** 1.7 +12 -1 jakarta-ant/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java Index: DOMElementWriterTest.java =================================================================== RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DOMElementWriterTest.java 9 Apr 2002 12:13:25 -0000 1.6 +++ DOMElementWriterTest.java 15 Jan 2003 14:02:49 -0000 1.7 @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2002 The Apache Software Foundation. All rights + * Copyright (c) 2000-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -118,5 +118,16 @@ assertTrue("0xE000", w.isLegalCharacter('\uE000')); assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD')); assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE')); + } + + public void testCDATAEndEncoding() { + assertEquals("]>", w.encodedata("]>")); + assertEquals("]]", w.encodedata("]]")); + assertEquals("&x5d;&x5d;>", w.encodedata("]]>")); + assertEquals("&x5d;&x5d;>A", w.encodedata("]]>A")); + assertEquals("A&x5d;&x5d;>", w.encodedata("A]]>")); + assertEquals("A&x5d;&x5d;>A", w.encodedata("A]]>A")); + assertEquals("A&x5d;&x5d;>B&x5d;&x5d;>C", + w.encodedata("A]]>B]]>C")); } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>