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 2020/12/27 07:06:55 UTC

[Bug 65030] New: LegacyXmlResultFormatter fails when properties contain illegal XML characters

https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

            Bug ID: 65030
           Summary: LegacyXmlResultFormatter fails when properties contain
                    illegal XML characters
           Product: Ant
           Version: 1.10.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optional Tasks
          Assignee: notifications@ant.apache.org
          Reporter: dominik.stadler@gmx.at
  Target Milestone: ---

When system properties contain some control characters, e.g. "ESC", ASCII 0x1b,
the resulting XML file is invalid and thus producing the test-report fails:

test-main:
    [javac] Compiling 1 source file to /tmp/git-svn/build/classes
    [javac] Support for javac --release has been added in Java9 ignoring it
    [mkdir] Created dir: /tmp/git-svn/build/dist/maven/poi
      [jar] Building jar:
/tmp/git-svn/build/dist/maven/poi/poi-5.0.0-SNAPSHOT.jar
    [javac] Compiling 1 source file to /tmp/git-svn/build/test-classes
    [javac] Support for javac --release has been added in Java9 ignoring it
      [jar] Building jar:
/tmp/git-svn/build/dist/maven/poi-tests/poi-5.0.0-SNAPSHOT-tests.jar
    [mkdir] Created dir: /tmp/git-svn/build/report
[junitreport] [Fatal Error] TEST-org.apache.poi.TestPOIDocumentMain.xml:1:826:
Ungültiges XML-Zeichen (Unicode: 0x1b) wurde im Wert des Attributs "value"
gefunden. Element ist "property".
[junitreport] The file
/tmp/git-svn/build/test-results/TEST-org.apache.poi.TestPOIDocumentMain.xml is
not a valid XML document. It is possibly corrupted.
[junitreport] Processing /tmp/git-svn/build/report/TESTS-TestSuites.xml to
/tmp/null1284078419
[junitreport] Loading stylesheet
jar:file:/opt/apache/apache-ant/apache-ant-1.10.9/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 321ms
[junitreport] Deleting: /tmp/null1284078419
     [echo] Published results from tests at build/report/index.html


It seems the XMLReportWriter should apply the same logic as the one from JUnit
5 itself received via this PR https://github.com/junit-team/junit5/pull/2275

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dominik.stadler@gmx.at

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

Stefan Bodewig <bo...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |1.10.10
             Status|NEW                         |RESOLVED

--- Comment #9 from Stefan Bodewig <bo...@apache.org> ---
I've fixed encoding of attribute values in master

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #4 from Stefan Bodewig <bo...@apache.org> ---
https://bz.apache.org/bugzilla/show_bug.cgi?id=6351 (eighteen years ago, seems
my memory still works sometimes ;-)

$ cat foo.xml 
<foo>&#0;</foo>
$ xmllint foo.xml 
foo.xml:1: parser error : xmlParseCharRef: invalid xmlChar value 0
<foo>&#0;</foo>
         ^

seems to confirm my reading of the spec back then. I've created
https://github.com/junit-team/junit5/pull/2275#issuecomment-751459822

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #2 from Dominik Stadler <do...@gmx.at> ---
Created attachment 37650
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=37650&action=edit
Sample invalid XML file produced by junitlauncher

See e.g. the property-value for key "env.LESS_TERMCAP_us"

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #3 from Stefan Bodewig <bo...@apache.org> ---
https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLStreamWriter.html
says

>  The XMLStreamWriter does not perform well formedness checking on its input. However the writeCharacters method is required to escape & , < and > For attribute values the writeAttribute method will escape the above characters plus " to ensure that all character content and attribute values are well formed.

Unfortunately it doesn't strip out characters that are illegal for any XML
content, something our own DOMElementWriter.encodeAttributeValue would do (this
is used by the traditional JUnit task). Simply using "our" encoder on top will
not help, as writeAttribute would re-encode the ampersands added when encoding
<>&" in encodeAttributeValue (which I believe to cause problems in bug 63436,
where we use our encode plus the encoding of writeCharacters).

So we probably need to extract DOMElementWriter.isLegalCharacter and filter by
that. I don't recall what I looked up years ago when we added isLegalCharacter
but I believe the code point 0 is completely prohibited inside of an XML
document, even when encoded as a numeric entity. The PR you mention would be
wrong if my recollection is right, we'll have to double-check.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #6 from Jaikiran Pai <ja...@apache.org> ---
> or we could replace them with an entity reference (i.e. 0 with &#0;) - which would still be illegal per se - but benefit from writeAttribute escaping the ampersand - this is what JUnit 5 itself or Surefire seem to be doing (unknowingly, maybe).

I think we should go with this approach - i.e. replace the illegal characters
with their entity references and then let writeAttribute escape them. That will
at least prevent any data loss in the reports (losing data like this while
debugging test failrues can be annoying and can lead to difficult to debug
issues).

> either fix would be pretty easy to implement but a bit tricky to test.

Wouldn't the test involve just checking, in the report, for a string which
represents this escaped value?

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #7 from Stefan Bodewig <bo...@apache.org> ---
> Wouldn't the test involve just checking, in the report, for a string which represents this escaped value?

Yes, we can write a Java test case that emits characters that are illegal in
XML and check the generated report. When I wrote it would be tricky I was
thinking about doing all that in an AntUnit style test and the tricky part was
to write something that creates characters illegal in XML inside of an XML
file.

I think I can get to this the coming weekend - or leave the changes to you.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

Dominik Stadler <do...@gmx.at> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |63436

--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
This is similar to bug #63436, but here we run into problems if the XML
contains invalid XML in values of the properties that are inclueded in the
report.


Referenced Bugs:

https://bz.apache.org/bugzilla/show_bug.cgi?id=63436
[Bug 63436] JUnitLauncher Task does not embedd stdout/stderr output in cdata
-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #5 from Stefan Bodewig <bo...@apache.org> ---
The XMLStreamWriter API is not very useful IMHO. It is not possible to add
entity references to an attribute as writeAttribute encodes the ampersand. For
the old JUnit Reports we would have replaced newlines (and a few other
whitespace chars) by a numeric entity reference, this is not possible here.

Anyway, we could strip characters that are not legal inside of XML documents
(like we do for the traditional JUnit case) or we could replace them with an
entity reference (i.e. 0 with &#0;) - which would still be illegal per se - but
benefit from writeAttribute escaping the ampersand - this is what JUnit 5
itself or Surefire seem to be doing (unknowingly, maybe).

I'm a bit on the fence here, either fix would be pretty easy to implement but a
bit tricky to test.

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030
Bug 65030 depends on bug 63436, which changed state.

Bug 63436 Summary: JUnitLauncher Task does not embedd stdout/stderr output in cdata
https://bz.apache.org/bugzilla/show_bug.cgi?id=63436

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

-- 
You are receiving this mail because:
You are the assignee for the bug.

[Bug 65030] LegacyXmlResultFormatter fails when properties contain illegal XML characters

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=65030

--- Comment #8 from Jaikiran Pai <ja...@apache.org> ---
> I think I can get to this the coming weekend - or leave the changes to you.

Hello Stefan,

If time permits you, please do take this up. I'm pretty sure I won't be able to
get to this the coming weekend.

-- 
You are receiving this mail because:
You are the assignee for the bug.