bodewig     2003/01/15 06:15:02

  Modified:    src/main/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        DOMElementWriter.java
               src/testcases/org/apache/tools/ant/util Tag: ANT_15_BRANCH
                        DOMElementWriterTest.java
  Log:
  merge CDATA fix from HEAD
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.11.2.1  +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.11
  retrieving revision 1.11.2.1
  diff -u -r1.11 -r1.11.2.1
  --- DOMElementWriter.java     15 Apr 2002 12:11:51 -0000      1.11
  +++ DOMElementWriter.java     15 Jan 2003 14:15:01 -0000      1.11.2.1
  @@ -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
  @@ -243,8 +243,15 @@
       /**
        * 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);
  @@ -254,7 +261,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;&gt;")
  +                .append(result.substring(cdEnd+3));
  +            result = sb.toString();
  +            cdEnd = result.indexOf("]]>");
  +        }
  +        
  +        return result;
       }
   
       /**
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.6.2.1   +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.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- DOMElementWriterTest.java 9 Apr 2002 12:13:25 -0000       1.6
  +++ DOMElementWriterTest.java 15 Jan 2003 14:15:01 -0000      1.6.2.1
  @@ -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;&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"));
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to