You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2010/06/08 15:28:24 UTC
DO NOT REPLY [Bug 49404] New: XMLJUnitResultFormatter does not
encode entity/character references
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Summary: XMLJUnitResultFormatter does not encode
entity/character references
Product: Ant
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: Optional Tasks
AssignedTo: notifications@ant.apache.org
ReportedBy: tztevnbfevnmz@mailinator.com
The following assert:
assertTrue("&&", false);
in a JUnit test case will produce the expected text output via ant
BriefJUnitResultFormatter:
junit.framework.AssertionFailedError: &&
But an unexpected one in via ant XMLJUnitResultFormatter:
<failure message="&&" ...>junit.framework.AssertionFailedError:
&&
When an XML parser reads that output, it will assume that the assertion message
was && and not && .
It looks like there are problems in formatError method, where:
1. the attribute value is set directly instead of taking care of
entity/character references first.
2. Tag content is set directly instead of wrapping it in CDATA.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #6 from Jesse Glick <jg...@netbeans.org> 2010-06-14 13:22:49 EDT ---
(In reply to comment #5)
> by now there may or may not be code that relies on the current behavior.
That's always possible, but the current behavior is known to be wrong, and
directly contradicts the Javadoc for the encode method.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #9 from Mark Lassau <ml...@atlassian.com> 2010-06-15 20:50:45 EDT ---
Thanks Stefan.
PS: While looking at the code I also noticed an encoding bug in the
encodedata() method.
It incorrectly tries to escape the "end of CDATA" marker "]]>" as
"]]>" this should be escaped as "]]]]><![CDATA[>" or similar.
See http://en.wikipedia.org/wiki/CDATA
"The preferred approach to using CDATA sections for encoding text that contains
the triad "]]>" is to use multiple CDATA sections by splitting each occurrence
of the triad just before the ">"."
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Przemek Bruski <tz...@mailinator.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Platform|PC |All
OS/Version|Linux |All
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #10 from Stefan Bodewig <bo...@apache.org> 2010-06-16 09:43:41 EDT ---
Yes, that approach looks better than the ad-hoc approach used so far.
svn revision 955226
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #7 from Mark Lassau <ml...@atlassian.com> 2010-06-15 00:04:04 EDT ---
(In reply to comment #6)
> (In reply to comment #5)
> > by now there may or may not be code that relies on the current behavior.
>
> That's always possible, but the current behavior is known to be wrong, and
> directly contradicts the Javadoc for the encode method.
Looking at the code, I have to agree with Jesse.
The isReference() check is basically saying "if the value parameter looks like
it was already encoded, then don't encode it again".
I imagine that someone added this when they saw behaviour that was
double-encoding a given string.
ie Some code was calling encode() twice (this is a bug). Instead of fixing that
bug, they put a "safety mechanism" in the encode() method.
Now the problem with this "safety mechanism" is that it is broken when you
legitimately want to encode an entity reference.
It seems to me that the "correct" fix would be to remove the isReference()
check and fix any code that wants to call this method twice.
If this is considered too hard or too risky, then could you create a new
implementation (eg called "encodeXml()" ) which will work correctly for Strings
with entity references?
You could then update the javadoc on the old method to clearly identify its
behaviour, and possibly even deprecate it.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Stefan Bodewig <bo...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |1.8.2
--- Comment #8 from Stefan Bodewig <bo...@apache.org> 2010-06-15 06:44:18 EDT ---
you've convinced me, Ant's own testsuite works without the special handling
except for the unit tests that are there to test just that.
Let's see whether anything breaks in Gump.
svn revision 954802
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Stefan Bodewig <bo...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
--- Comment #1 from Stefan Bodewig <bo...@apache.org> 2010-06-08 10:45:10 EDT ---
which version of Ant is this?
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #5 from Stefan Bodewig <bo...@apache.org> 2010-06-14 10:00:36 EDT ---
Back then we used BugRat and I don't think the bugs have ever been imported
into
Bugzilla. 413 was http://marc.info/?l=ant-dev&m=97474406900100&w=2 which
doesn't
explain why I created the special case for ampersands that start an entity.
I dont remember why I added it and my personal mailing list archives
don't help either - it must have been something I had in mind and didn't
discuss with anybody.
Still, by now there may or may not be code that relies on the current behavior.
I don't see an easy way out.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Stefan Bodewig <bo...@apache.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |NEW
Version|unspecified |1.8.1
--- Comment #2 from Stefan Bodewig <bo...@apache.org> 2010-06-08 11:04:32 EDT ---
found the reason, not sure how to fix it.
XMLJUnitResultFormatter uses DOMElementWriter which encodes both attributes and
element content. The following part of the encode method
case '&':
int nextSemi = value.indexOf(";", i);
if (nextSemi < 0
|| !isReference(value.substring(i, nextSemi + 1))) {
sb.append("&");
} else {
sb.append('&');
}
break;
contains some special handling that explicitly suppresses encoding of an
ampersand if it starts an entity reference.
I don't recall why the code does what it does but changing it is likely going
to cause other trouble.
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Jesse Glick <jg...@netbeans.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jglick@netbeans.org
Component|Optional Tasks |Core
Severity|normal |major
--- Comment #4 from Jesse Glick <jg...@netbeans.org> 2010-06-10 16:14:21 EDT ---
Not limited to this task.
<project default="run">
<target name="run">
<echoxml><x><![CDATA[&&]]></x></echoxml>
</target>
</project>
should print
<x>&amp;&</x>
but instead prints
<x>&&</x>
I would recommend isReference() be deprecated and perhaps deleted, and encode()
to unconditionally replace & with &.
FWIW, the faulty code was introduced long ago:
------------------------------------------------------------------------
r268330 | bodewig | 2000-12-07 09:52:03 -0500 (Thu, 07 Dec 2000) | 7 lines
Moved the common code from XmlLogger and XMLJUnitResultLogger into a
new class.
Wrap nested text into <![CDATA[ ]]> and replace special characters in
attribute values correctly.
PR: 413
------------------------------------------------------------------------
(Bug #413 does not appear related, so I guess this was some earlier tracking
system?)
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
Mark Lassau <ml...@atlassian.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mlassau@atlassian.com
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
DO NOT REPLY [Bug 49404] XMLJUnitResultFormatter does not encode
entity/character references
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49404
--- Comment #3 from Mark Lassau <ml...@atlassian.com> 2010-06-08 22:16:12 EDT ---
This causes the following bug in Atlassian Bamboo:
http://jira.atlassian.com/browse/BAM-5773
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.