You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Adam Murdoch <ad...@yahoo.com> on 2001/12/15 15:09:39 UTC

[PATCH] addConfigured in custom tasks; whitespace going missing

Hi,

A couple of tiny patches:

* addConfigured methods for custom tasks were being called twice.  This
problem was caused by RuntimeConfigurable.maybeConfigure() being called
twice on the task's RuntimeConfigurable - once in
UnknownElement.maybeConfigure(), and once in the custom task's perform()
method.

Changed UnknownElement.execute() to call execute() on the custom task,
rather than perform().

* Whitespace in text content was sometimes being thrown away, depending on
how the SAX parser decided to divide it across calls to
ContentHandler.characters().


Adam

DOMElementWriter fix for control characters.

Posted by Jim White <ji...@pagesmiths.com>.
Howdy Gang.

Gotta say first thing that I love Ant and it has been my primary scripting 
tool for most of this year.

Anyhow, I've started using CruiseControl and ran into a nasty problem 
caused by some user code (triggered by Jtest) that was sending ANSI control 
characters to the console.  That winds up in the log.xml generated by 
DOMElementWriter.  Unfortunately the XML file is invalid since only '\t', 
'\r', and '\n' controls are allowed, others must be coded as their 
entities, but DOMElementWriter was not doing that.  That is true for both 
TEXT and CDATA.

See: http://www.w3.org/TR/1998/REC-xml-19980210#charsets

Following is my patch to fix this problem.

jim

cvs diff -c DOMElementWriter.java
Index: DOMElementWriter.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/util/DOMElementWriter.java,v
retrieving revision 1.5
diff -c -r1.5 DOMElementWriter.java
*** DOMElementWriter.java       2001/10/28 21:27:20     1.5
--- DOMElementWriter.java       2001/12/18 18:37:21
***************
*** 142,148 ****

               case Node.CDATA_SECTION_NODE:
                   out.write("<![CDATA[");
!                 out.write(((Text)child).getData());
                   out.write("]]>");
                   break;

--- 142,148 ----

               case Node.CDATA_SECTION_NODE:
                   out.write("<![CDATA[");
!                 out.write(encodedata(((Text)child).getData()));
                   out.write("]]>");
                   break;

***************
*** 183,189 ****
       }

       /**
!      * Escape &lt;, &gt; &amp; &apos; and &quot; as their entities.
        */
       public String encode(String value) {
           sb.setLength(0);
--- 183,189 ----
       }

       /**
!      * Escape &lt;, &gt; &amp; &apos; and &quot; and < &#x20; as their 
entities.
        */
       public String encode(String value) {
           sb.setLength(0);
***************
*** 211,217 ****
--- 211,261 ----
                       sb.append('&');
                   }
                   break;
+             case '\t':
+             case '\n':
+             case '\r':
+                 sb.append(c);
+                 break;
+
               default:
+                 if (c < 0x20) {
+                     sb.append("&#x");
+                     sb.append(Integer.toHexString(c));
+                     sb.append(';');
+                     break;
+                 }
+
+                 sb.append(c);
+                 break;
+             }
+         }
+         return sb.toString();
+     }
+
+     /**
+      * Escape < &#x20; as their entities.
+      * See XML 1.0 2.2 <http://www.w3.org/TR/1998/REC-xml-19980210#charsets>.
+      */
+     public String encodedata(final String value)
+     {
+         sb.setLength(0);
+         for (int i = 0; i < value.length(); ++i) {
+             char c = value.charAt(i);
+             switch (c) {
+             case '\t':
+             case '\n':
+             case '\r':
+                 sb.append(c);
+                 break;
+
+             default:
+                 if (c < 0x20) {
+                     sb.append("&#x");
+                     sb.append(Integer.toHexString(c));
+                     sb.append(';');
+                     break;
+                 }
+
                   sb.append(c);
                   break;
               }

*****CVS exited normally with code 1*****

cvs diff -c DOMElementWriterTest.java
Index: DOMElementWriterTest.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java,v
retrieving revision 1.3
diff -c -r1.3 DOMElementWriterTest.java
*** DOMElementWriterTest.java   2001/10/23 10:35:14     1.3
--- DOMElementWriterTest.java   2001/12/18 19:38:26
***************
*** 100,104 ****
--- 100,107 ----
           assertEquals("&quot;", w.encode("\""));
           assertEquals("&lt;", w.encode("<"));
           assertEquals("&amp;", w.encode("&"));
+         assertEquals("&#x17;", w.encode("\u0017"));
+         assertEquals("&#20;\"20;&", w.encodedata("&#20;\"20;&"));
+         assertEquals("&#x17;", w.encodedata("\u0017"));
       }
   }

*****CVS exited normally with code 1*****


----------------------------------------------------------------
James P. White     Pagesmiths' home is http://www.pagesmiths.com
Live free http://www.ushistory.org/franklin/quotable/quote04.htm
Try Kawa, the Java-based Scheme http://www.gnu.org/software/kawa


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH] addConfigured in custom tasks; whitespace going missing

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Woohoo!  Mystery solved then.


----- Original Message -----
From: "Adam Murdoch" <ad...@yahoo.com>
To: "Ant Developers List" <an...@jakarta.apache.org>
Sent: Saturday, December 15, 2001 9:47 AM
Subject: RE: [PATCH] addConfigured in custom tasks; whitespace going missing


>
> Yep - that's how I found it.
>
> > -----Original Message-----
> > From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com]
> > Sent: Sunday, 16 December 2001 12:47 AM
> > To: Ant Developers List
> > Subject: Re: [PATCH] addConfigured in custom tasks; whitespace going
> > missing
> >
> >
> > From: "Adam Murdoch" <ad...@yahoo.com>
> > Sent: Saturday, December 15, 2001 9:09 AM
> >
> >
> > > * Whitespace in text content was sometimes being thrown away,
> > depending on
> > > how the SAX parser decided to divide it across calls to
> > > ContentHandler.characters().
> >
> > Will this fix the test that fails for me when running 'build test'?
> >
> > Testsuite: org.apache.tools.ant.types.DescriptionTest
> > Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.12 sec
> >
> > Testcase: test2(org.apache.tools.ant.types.DescriptionTest):    FAILED
> > Multi line description failed expected:<Multi Line
> > Project Description> but was:<Multi LineProject Description>
> > junit.framework.AssertionFailedError: Multi line description failed
> > expected:<Mu
> > lti Line
> > Project Description> but was:<Multi LineProject Description>
> >         at junit.framework.Assert.fail(Assert.java:51)
> >
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: [PATCH] addConfigured in custom tasks; whitespace going missing

Posted by Adam Murdoch <ad...@yahoo.com>.
Yep - that's how I found it.

> -----Original Message-----
> From: Erik Hatcher [mailto:jakarta-ant@ehatchersolutions.com]
> Sent: Sunday, 16 December 2001 12:47 AM
> To: Ant Developers List
> Subject: Re: [PATCH] addConfigured in custom tasks; whitespace going
> missing
> 
> 
> From: "Adam Murdoch" <ad...@yahoo.com>
> Sent: Saturday, December 15, 2001 9:09 AM
> 
> 
> > * Whitespace in text content was sometimes being thrown away, 
> depending on
> > how the SAX parser decided to divide it across calls to
> > ContentHandler.characters().
> 
> Will this fix the test that fails for me when running 'build test'?
> 
> Testsuite: org.apache.tools.ant.types.DescriptionTest
> Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.12 sec
> 
> Testcase: test2(org.apache.tools.ant.types.DescriptionTest):    FAILED
> Multi line description failed expected:<Multi Line
> Project Description> but was:<Multi LineProject Description>
> junit.framework.AssertionFailedError: Multi line description failed
> expected:<Mu
> lti Line
> Project Description> but was:<Multi LineProject Description>
>         at junit.framework.Assert.fail(Assert.java:51)
> 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [PATCH] addConfigured in custom tasks; whitespace going missing

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
From: "Adam Murdoch" <ad...@yahoo.com>
Sent: Saturday, December 15, 2001 9:09 AM


> * Whitespace in text content was sometimes being thrown away, depending on
> how the SAX parser decided to divide it across calls to
> ContentHandler.characters().

Will this fix the test that fails for me when running 'build test'?

Testsuite: org.apache.tools.ant.types.DescriptionTest
Tests run: 2, Failures: 1, Errors: 0, Time elapsed: 0.12 sec

Testcase: test2(org.apache.tools.ant.types.DescriptionTest):    FAILED
Multi line description failed expected:<Multi Line
Project Description> but was:<Multi LineProject Description>
junit.framework.AssertionFailedError: Multi line description failed
expected:<Mu
lti Line
Project Description> but was:<Multi LineProject Description>
        at junit.framework.Assert.fail(Assert.java:51)




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>