Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cater for nested CDDATA in XML reporters #643

Closed
lwasylow opened this Issue Apr 15, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@lwasylow
Copy link
Member

lwasylow commented Apr 15, 2018

Current reporter when printing xml don't escape CDDATA when it's part of the string being printed e.g. failure message. This causing a xml to break.
Sample test:

create or replace package check_junit_reporting is
      --%suite()

      --%test(Test with ccdata)
      procedure test_do_stuff;

    end;
create or replace package body check_junit_reporting is
      procedure test_do_stuff is
      begin
        ut.expect('1').to_equal('<![CDATA[some stuff]]>');;
      end;
    end;

And result

<testsuites tests="1" skipped="0" error="0" failure="1" name="" time=".078591" >
<testsuite tests="1" id="1" package="check_junit_reporting"  skipped="0" error="0" failure="1" name="check_junit_reporting" time=".078326" >
<testcase classname="check_junit_reporting"  assertions="2" skipped="0" error="0" failure="1" name="Test with ccdata" time=".077445"  status="Failure">
<failure>
<![CDATA[
Actual: '1' (varchar2) was expected to equal: '<![CDATA[some stuff]]>' (varchar2) 
"at "UT3_TESTER.CHECK_JUNIT_REPORTING.TEST_DO_STUFF", line 4 ut.expect('1').to_equal('<![CDATA[some stuff]]>');
"
]]>
</failure>
</testcase>
</testsuite>
</testsuites>

And when you validate
XML Parsing Error: not well-formed
Line Number 9, Column 52:

Since CDDATA is not really something we can escape the only solution I found was to use ]]]]><![CDATA[>

<testsuites tests="1" skipped="0" error="0" failure="1" name="" time=".078591" >
<testsuite tests="1" id="1" package="check_junit_reporting"  skipped="0" error="0" failure="1" name="check_junit_reporting" time=".078326" >
<testcase classname="check_junit_reporting"  assertions="2" skipped="0" error="0" failure="1" name="Test with ccdata" time=".077445"  status="Failure">
<failure>
<![CDATA[
Actual: '1' (varchar2) was expected to equal: '<![CDATA[some stuff]]>' (varchar2) 
"at "UT3_TESTER.CHECK_JUNIT_REPORTING.TEST_DO_STUFF", line 4 ut.expect('1').to_equal('<![CDATA[some stuff]]]]><![CDATA[>');
"
]]>
</failure>
</testcase>
</testsuite>
</testsuites>

@lwasylow lwasylow changed the title Escape CDDATA in XML reporters Cater for nested CDDATA in XML reporters Apr 15, 2018

@jgebal

This comment has been minimized.

Copy link
Member

jgebal commented Apr 19, 2018

Using ]]]]><![CDATA[> will remove the CDATA tag from nested XML, which in the example is actually representing some really meaningful information
By doing so, we're loosing some data.

How about not using CDATA but escaping the content of <failure> by running it through dbms_xml.convert()?
That would look like:

<testsuites tests="1" skipped="0" error="0" failure="1" name="" time=".078591" >
<testsuite tests="1" id="1" package="check_junit_reporting"  skipped="0" error="0" failure="1" name="check_junit_reporting" time=".078326" >
<testcase classname="check_junit_reporting"  assertions="2" skipped="0" error="0" failure="1" name="Test with ccdata" time=".077445"  status="Failure">
<failure>Actual: &apos;1&apos; (varchar2) was expected to equal: &apos;&lt;![CDATA[some stuff]]&gt;&apos; (varchar2)
  &quot;at &quot;UT3_TESTER.CHECK_JUNIT_REPORTING.TEST_DO_STUFF&quot;, line 4 ut.expect(&apos;1&apos;).to_equal(&apos;&lt;![CDATA[some stuff]]&gt;&apos;);&quot;</failure>
</testcase>
</testsuite>
</testsuites>
@lwasylow

This comment has been minimized.

Copy link
Member Author

lwasylow commented Apr 21, 2018

Sounds good but would a cddata nested prevented Dbms convert from escaping it?would have to check.

@jgebal

This comment has been minimized.

Copy link
Member

jgebal commented Apr 21, 2018

If you convert the content it is no longer considered to be CDATA. CDATA tag doesn't expect converted content.
It is either one or another.
We should probably check on Jenkins to be sure it is ok to convert back the content that was converted without CDATA anyeay

@lwasylow

This comment has been minimized.

Copy link
Member Author

lwasylow commented May 3, 2018

Sounds like a good idea 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.