Browse Source

Don't allow ]]> within CDATA sections.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273801 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
7b8097afa8
3 changed files with 35 additions and 6 deletions
  1. +2
    -2
      WHATSNEW
  2. +21
    -3
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  3. +12
    -1
      src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java

+ 2
- 2
WHATSNEW View File

@@ -17,6 +17,8 @@ Changes that could break older environments:
* 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.
@@ -168,8 +170,6 @@ Other changes:
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
====================================



+ 21
- 3
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -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 @@ public class DOMElementWriter {
/**
* Drop characters that are illegal in XML documents.
*
* <p>Also ensure that we are not including an <code>]]&gt;</code>
* marker by replacing that sequence with
* <code>&amp;x5d;&amp;x5d;&amp;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 @@ public class DOMElementWriter {
sb.append(c);
}
}
return sb.toString();

String result = sb.toString();
int cdEnd = result.indexOf("]]>");
while (cdEnd != -1) {
sb.setLength(cdEnd);
sb.append("&x5d;&x5d;&gt;")
.append(result.substring(cdEnd+3));
result = sb.toString();
cdEnd = result.indexOf("]]>");
}
return result;
}

/**


+ 12
- 1
src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java View File

@@ -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
@@ -119,4 +119,15 @@ public class DOMElementWriterTest extends TestCase {
assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD'));
assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
}

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",
w.encodedata("A]]>B]]>C"));
}
}

Loading…
Cancel
Save