You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Bhuvaneswaran A <bh...@collab.net> on 2009/12/04 07:05:51 UTC

[PATCH] Handle special characters in Junit report

The failure message for few tests contain special characters, ex:
prop_tests.py. As a result, it creates an invalid xml file and not being
displayed in Hudson.

This commit fixes this issue, also tracked in issue 3541. With this fix,
the test results are displayed in Hudson, especially the results
specific to 1.6.x solaris build.
  http://subversion.tigris.org/issues/show_bug.cgi?id=3541

[[
Fix for issue 3541. When generating junit reports, remove special 
characters, if any, from test failure messages.

* tools/dev/gen_junit_report.py
  (remove_special_characters): New method to remove special characters.
  (junit_testcase_fail, junit_testcase_xfail): Use 
  remove_special_characters() method to remove special characters in 
  test failure messages.
]]

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@btopenworld.com>.
I (Julian Foad) wrote:
[...]
> But... this is only a test result logging application. If it works with
> what the Subversion test suite produces, then it works.

I mean: so if it works, go ahead and commit it - it doesn't need to be
"perfect".

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Julian Foad wrote:
> I searched on the web and didn't find a really really simple way to
> escape a set of characters. I think something like
>
>   for c in chars_to_remove:
>     data = data.replace(c, '%%%0x' % ord(c))
>
> would do it.
>   

Please read what I wrote earlier. Second, this is URL escaping, not XML
quoting. But first, there is no way to represent such control chars in
XML. Only CR and LF are valid according the the XML spec. Others are
not; and you can't use character references, e.g., &#27; to represent
ESC. That's not valid XML.

-- Brane

Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 13:41 +0000, Julian Foad wrote:
> Bhuvaneswaran A wrote:
> > Branko, Julian: Thank you for the review comments.
> > 
> > Incorporated the above suggestion and committed in r887178. Now that the
> > script is stable, as discussed in this thread [1], shall I nominate this
> > script to 1.6.x branch?
> > [1]
> > http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2410330
> 
> Do we need an up-to-date copy of it in branches/1.6.x - in other words,
> do we want the Hudson system to use the script that it finds in the
> "dev/tools/" directory of the branch it is building? I would have
> thought it should just use the copy that's in trunk, even when it is
> building and testing a branch, because the schedule and purpose of
> maintaining subversion-1.6.x is separate from the schedule and purpose
> of maintaining the testing system.

That's right. Right now we use the script in trunk to generate report
for 1.6.x build. The build script is ugly to execute the script from
relative path. This is not an issue right now, as both builds are tied
to same box. But in case, we tie trunk and 1.6.x build to separate box
we might have to co this script from trunk while we build 1.6.x branch,
solely due to the fact that it does not exist in 1.6.x branch.

That's the reason I prefer to backport this script to 1.6.x branch.
-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@btopenworld.com>.
Bhuvaneswaran A wrote:
> Branko, Julian: Thank you for the review comments.
> 
> Incorporated the above suggestion and committed in r887178. Now that the
> script is stable, as discussed in this thread [1], shall I nominate this
> script to 1.6.x branch?
> [1]
> http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2410330

Do we need an up-to-date copy of it in branches/1.6.x - in other words,
do we want the Hudson system to use the script that it finds in the
"dev/tools/" directory of the branch it is building? I would have
thought it should just use the copy that's in trunk, even when it is
building and testing a branch, because the schedule and purpose of
maintaining subversion-1.6.x is separate from the schedule and purpose
of maintaining the testing system.

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 15:29 +0100, Branko Čibej wrote:
> Bhuvaneswaran A wrote:
> > On Fri, 2009-12-04 at 12:36 +0000, Julian Foad wrote:
> >   
> >> Bhuvaneswaran A wrote:
> >>     
> >>> Please find attached the revised patch. I incorporated following
> >>> feedback:
> >>>   a) Fix the array slicing part
> >>>   b) Escape using ord() instead of removing those characters
> >>>   c) Handle "]]>" in CDATA section
> >>>   d) Define the ascii table globally (once) and re-use
> >>>
> >>> I also verified this fix by generating the junit files for tests having
> >>> special characters and simulating a test that has "]]>" in failure text.
> >>> With this patch, it generates valid junit file.
> >>>       
> >> It looks great. You could also move the definition of 'chars_to_remove'
> >> out of the function, but either way it's fine. Go on, commit it!
> >>     
> >
> > Branko, Julian: Thank you for the review comments.
> >
> > Incorporated the above suggestion and committed in r887178.
> 
> Wait, you committed a script that does URL quoting on XML contents? Did
> you look at the output?

Branko, yes. The data goes in CDATA section in xml. With this fix, a
valid xml file is generated even if the failure message contain a)
control characters. b) contains "]]>" pattern.

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 14:44 +0000, Julian Foad wrote:
> Sure. The idea is to make the occasional unexpected control character
> appear as something that is valid in an XML CDATA section and is
> human-readable. URL escaping rules seemed a fine choice. Have I missed
> something?
> 
> > > Incorporated the above suggestion and committed in r887178.
> > 
> > Wait, you committed a script that does URL quoting on XML contents?
> Did
> > you look at the output?
> 
> I didn't look at any real output, only a hand-crafted test string. Did
> you? Why do you ask? 

Here's the real output.
  -- prop_tests.py.junit.xml.invalid -- before this patch
  -- prop_tests.py.junit.xml.valid -- after this patch

To verify the case with "]]>" pattern, you can edit the tests.log file
with this pattern in any one of failure message. If you run the script,
without this patch, it will generate an invalid xml file. With this
patch, it will generate a valid xml file.

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Julian Foad wrote:
> Branko Čibej wrote:
>   
>>> Incorporated the above suggestion and committed in r887178.
>>>       
>> Wait, you committed a script that does URL quoting on XML contents? Did
>> you look at the output?
>>     
>
> I didn't look at any real output, only a hand-crafted test string. Did
> you? Why do you ask?
>   

So we're somehow getting a backspace (^H, chr(8)) in the test output
(how??) and it gets converted to %8. That's not very helpful.

I'm going to replace them with the unicode characters in the Control
Pictures block, that's U+2400 to U+241F. Should be quite a bit
frientlier to the eyes, and not quite so ambiguous.

-- Brane

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@wandisco.com>.
Branko Čibej wrote:
> Bhuvaneswaran A wrote:
> > On Fri, 2009-12-04 at 12:36 +0000, Julian Foad wrote:
> >   
> >> Bhuvaneswaran A wrote:
> >>     
> >>> Please find attached the revised patch. I incorporated following
> >>> feedback:
> >>>   a) Fix the array slicing part
> >>>   b) Escape using ord() instead of removing those characters
> >>>   c) Handle "]]>" in CDATA section
> >>>   d) Define the ascii table globally (once) and re-use
> >>>
> >>> I also verified this fix by generating the junit files for tests having
> >>> special characters and simulating a test that has "]]>" in failure text.
> >>> With this patch, it generates valid junit file.
> >>>       
> >> It looks great. You could also move the definition of 'chars_to_remove'
> >> out of the function, but either way it's fine. Go on, commit it!
> >>     
> >
> > Branko, Julian: Thank you for the review comments.

Branko wrote (elsewhere in the thread):
> Julian Foad wrote:
> > I searched on the web and didn't find a really really simple way to
> > escape a set of characters. I think something like
> >
> >   for c in chars_to_remove:
> >     data = data.replace(c, '%%%0x' % ord(c))
> >
> > would do it.
> 
> Please read what I wrote earlier. Second, this is URL escaping, not XML
> quoting. But first, there is no way to represent such control chars in
> XML. Only CR and LF are valid according the the XML spec. Others are
> not; and you can't use character references, e.g., &#27; to represent
> ESC. That's not valid XML.

Sure. The idea is to make the occasional unexpected control character
appear as something that is valid in an XML CDATA section and is
human-readable. URL escaping rules seemed a fine choice. Have I missed
something?

> > Incorporated the above suggestion and committed in r887178.
> 
> Wait, you committed a script that does URL quoting on XML contents? Did
> you look at the output?

I didn't look at any real output, only a hand-crafted test string. Did
you? Why do you ask?

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Bhuvaneswaran A wrote:
> On Fri, 2009-12-04 at 12:36 +0000, Julian Foad wrote:
>   
>> Bhuvaneswaran A wrote:
>>     
>>> Please find attached the revised patch. I incorporated following
>>> feedback:
>>>   a) Fix the array slicing part
>>>   b) Escape using ord() instead of removing those characters
>>>   c) Handle "]]>" in CDATA section
>>>   d) Define the ascii table globally (once) and re-use
>>>
>>> I also verified this fix by generating the junit files for tests having
>>> special characters and simulating a test that has "]]>" in failure text.
>>> With this patch, it generates valid junit file.
>>>       
>> It looks great. You could also move the definition of 'chars_to_remove'
>> out of the function, but either way it's fine. Go on, commit it!
>>     
>
> Branko, Julian: Thank you for the review comments.
>
> Incorporated the above suggestion and committed in r887178.

Wait, you committed a script that does URL quoting on XML contents? Did
you look at the output?

-- Brane

Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 12:36 +0000, Julian Foad wrote:
> Bhuvaneswaran A wrote:
> > Please find attached the revised patch. I incorporated following
> > feedback:
> >   a) Fix the array slicing part
> >   b) Escape using ord() instead of removing those characters
> >   c) Handle "]]>" in CDATA section
> >   d) Define the ascii table globally (once) and re-use
> > 
> > I also verified this fix by generating the junit files for tests having
> > special characters and simulating a test that has "]]>" in failure text.
> > With this patch, it generates valid junit file.
> 
> It looks great. You could also move the definition of 'chars_to_remove'
> out of the function, but either way it's fine. Go on, commit it!

Branko, Julian: Thank you for the review comments.

Incorporated the above suggestion and committed in r887178. Now that the
script is stable, as discussed in this thread [1], shall I nominate this
script to 1.6.x branch?
[1]
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2410330

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@btopenworld.com>.
Bhuvaneswaran A wrote:
> Please find attached the revised patch. I incorporated following
> feedback:
>   a) Fix the array slicing part
>   b) Escape using ord() instead of removing those characters
>   c) Handle "]]>" in CDATA section
>   d) Define the ascii table globally (once) and re-use
> 
> I also verified this fix by generating the junit files for tests having
> special characters and simulating a test that has "]]>" in failure text.
> With this patch, it generates valid junit file.

It looks great. You could also move the definition of 'chars_to_remove'
out of the function, but either way it's fine. Go on, commit it!

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
Please find attached the revised patch. I incorporated following
feedback:
  a) Fix the array slicing part
  b) Escape using ord() instead of removing those characters
  c) Handle "]]>" in CDATA section
  d) Define the ascii table globally (once) and re-use

I also verified this fix by generating the junit files for tests having
special characters and simulating a test that has "]]>" in failure text.
With this patch, it generates valid junit file.

[[
Fix for issue 3541. When generating junit reports, escape special
characters, if any, from test failure messages.

* tools/dev/gen_junit_report.py
  (escape_special_characters): New method to escape special characters.
  (junit_testcase_fail, junit_testcase_xfail): Use 
  escape_special_characters() method to escape special characters in 
  test failure messages.
]]
On Fri, 2009-12-04 at 11:19 +0000, Julian Foad wrote:
> Bhuvaneswaran A wrote:
> > On Fri, 2009-12-04 at 10:22 +0000, Julian Foad wrote:
> > > Branko Čibej wrote:
> > > > Bhuvaneswaran A wrote:
> > > > > The failure message for few tests contain special characters, ex:
> > > 
> > > What do you mean by "special" characters? Unprintable characters?
> > > Non-UTF8 characters? Invalid XML characters? Characters that are XML
> > > syntax characters such as "<"?
> > 
> > When I mean special characters, I mean control characters, ex "^H".
> > Refer to the attachment in issue 3541 for a sample character.
> > 
> > > > > prop_tests.py. As a result, it creates an invalid xml file and not being
> > > > > displayed in Hudson.
> > > > >
> > > > > This commit fixes this issue, also tracked in issue 3541. With this fix,
> > > > > the test results are displayed in Hudson, especially the results
> > > > > specific to 1.6.x solaris build.
> > > > >   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
> > > > >   
> > > > > Index: tools/dev/gen_junit_report.py
> > > > > =======================================
> > > > > --- tools/dev/gen_junit_report.py	(revision 886204)
> > > > > +++ tools/dev/gen_junit_report.py	(working copy)
> > > > > @@ -46,6 +46,16 @@
> > > > > data = data.replace(char, encode[char])
> > > > > return data
> > > > > +def remove_special_characters(data):
> > > > > + """remove special characters in test failure reasons"""
> > > > > + if not data:
> > > > > + return data
> > > > > + chars_table = "".join([chr(n) for n in xrange(256)])
> > > > > + # remove all special characters upto ascii value 31, except line
> > > > > feed (10)
> > > > > + # and carriage return (13)
> > > > > + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> > > > > chars_table[14:31]
> > > 
> > > Isn't the indexing off by one? Should be [0:10] ... [11:13] ... [14:32].
> > 
> > As per the comment, I wanted to preserve LF (10) and CR (13). [0:9] ...
> > [11:12] ... [14:31] works for me.
> 
> In array slicing, the range start is inclusive but the end is exclusive,
> so [11:12] just gives the single character [11], whereas [11:13] would
> give [11] and [12] which is what you want.
> 
> > > > Also, wouldn't it be more proper to find out why the tests put control
> > > > characters in the failure description than to just blindly throw them away?
> > > 
> > > Or just escape the "special" characters.
> > 
> > Good point. I used to encode using utf-8, but it doesn't seem to
> > detect/encode these characters, resulting in unchanged behaviour. I used
> > something like:
> > 
> > reason = u'%s'.encode('utf-8') % reason
> > reason = unicode(reason, 'utf-8')
> 
> Those statements are just converting from UTF-8 to internal Unicode
> representation, not doing any escaping. Control characters (and all
> characters) are valid in both UTF-8 and internal Unicode
> representations, so no escaping is needed for the conversion.
> 
> I searched on the web and didn't find a really really simple way to
> escape a set of characters. I think something like
> 
>   for c in chars_to_remove:
>     data = data.replace(c, '%%%0x' % ord(c))
> 
> would do it.
> 
> - Julian
> 
> 


-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@wandisco.com>.
Bhuvaneswaran A wrote:
> On Fri, 2009-12-04 at 10:22 +0000, Julian Foad wrote:
> > Branko Čibej wrote:
> > > Bhuvaneswaran A wrote:
> > > > The failure message for few tests contain special characters, ex:
> > 
> > What do you mean by "special" characters? Unprintable characters?
> > Non-UTF8 characters? Invalid XML characters? Characters that are XML
> > syntax characters such as "<"?
> 
> When I mean special characters, I mean control characters, ex "^H".
> Refer to the attachment in issue 3541 for a sample character.
> 
> > > > prop_tests.py. As a result, it creates an invalid xml file and not being
> > > > displayed in Hudson.
> > > >
> > > > This commit fixes this issue, also tracked in issue 3541. With this fix,
> > > > the test results are displayed in Hudson, especially the results
> > > > specific to 1.6.x solaris build.
> > > >   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
> > > >   
> > > > Index: tools/dev/gen_junit_report.py
> > > > =======================================
> > > > --- tools/dev/gen_junit_report.py	(revision 886204)
> > > > +++ tools/dev/gen_junit_report.py	(working copy)
> > > > @@ -46,6 +46,16 @@
> > > > data = data.replace(char, encode[char])
> > > > return data
> > > > +def remove_special_characters(data):
> > > > + """remove special characters in test failure reasons"""
> > > > + if not data:
> > > > + return data
> > > > + chars_table = "".join([chr(n) for n in xrange(256)])
> > > > + # remove all special characters upto ascii value 31, except line
> > > > feed (10)
> > > > + # and carriage return (13)
> > > > + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> > > > chars_table[14:31]
> > 
> > Isn't the indexing off by one? Should be [0:10] ... [11:13] ... [14:32].
> 
> As per the comment, I wanted to preserve LF (10) and CR (13). [0:9] ...
> [11:12] ... [14:31] works for me.

In array slicing, the range start is inclusive but the end is exclusive,
so [11:12] just gives the single character [11], whereas [11:13] would
give [11] and [12] which is what you want.

> > > Also, wouldn't it be more proper to find out why the tests put control
> > > characters in the failure description than to just blindly throw them away?
> > 
> > Or just escape the "special" characters.
> 
> Good point. I used to encode using utf-8, but it doesn't seem to
> detect/encode these characters, resulting in unchanged behaviour. I used
> something like:
> 
> reason = u'%s'.encode('utf-8') % reason
> reason = unicode(reason, 'utf-8')

Those statements are just converting from UTF-8 to internal Unicode
representation, not doing any escaping. Control characters (and all
characters) are valid in both UTF-8 and internal Unicode
representations, so no escaping is needed for the conversion.

I searched on the web and didn't find a really really simple way to
escape a set of characters. I think something like

  for c in chars_to_remove:
    data = data.replace(c, '%%%0x' % ord(c))

would do it.

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Bhuvaneswaran A wrote:
> On Fri, 2009-12-04 at 10:22 +0000, Julian Foad wrote:
>   
>> Branko Čibej wrote:
>>     
>> Or just escape the "special" characters.
>>     
>
> Good point. I used to encode using utf-8, but it doesn't seem to
> detect/encode these characters, resulting in unchanged behaviour. I used
> something like:
>
> reason = u'%s'.encode('utf-8') % reason
> reason = unicode(reason, 'utf-8')
>   

That's because ASCII control characters are valid UTF-8 sequences,
there's no encoding to be done in this case.

-- Brane

Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 10:22 +0000, Julian Foad wrote:
> Branko Čibej wrote:
> > Bhuvaneswaran A wrote:
> > > The failure message for few tests contain special characters, ex:
> 
> What do you mean by "special" characters? Unprintable characters?
> Non-UTF8 characters? Invalid XML characters? Characters that are XML
> syntax characters such as "<"?

When I mean special characters, I mean control characters, ex "^H".
Refer to the attachment in issue 3541 for a sample character.

> > > prop_tests.py. As a result, it creates an invalid xml file and not being
> > > displayed in Hudson.
> > >
> > > This commit fixes this issue, also tracked in issue 3541. With this fix,
> > > the test results are displayed in Hudson, especially the results
> > > specific to 1.6.x solaris build.
> > >   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
> > >   
> > > Index: tools/dev/gen_junit_report.py
> > > =======================================
> > > --- tools/dev/gen_junit_report.py	(revision 886204)
> > > +++ tools/dev/gen_junit_report.py	(working copy)
> > > @@ -46,6 +46,16 @@
> > > data = data.replace(char, encode[char])
> > > return data
> > > +def remove_special_characters(data):
> > > + """remove special characters in test failure reasons"""
> > > + if not data:
> > > + return data
> > > + chars_table = "".join([chr(n) for n in xrange(256)])
> > > + # remove all special characters upto ascii value 31, except line
> > > feed (10)
> > > + # and carriage return (13)
> > > + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> > > chars_table[14:31]
> 
> Isn't the indexing off by one? Should be [0:10] ... [11:13] ... [14:32].

As per the comment, I wanted to preserve LF (10) and CR (13). [0:9] ...
[11:12] ... [14:31] works for me.

> > Also, wouldn't it be more proper to find out why the tests put control
> > characters in the failure description than to just blindly throw them away?
> 
> Or just escape the "special" characters.

Good point. I used to encode using utf-8, but it doesn't seem to
detect/encode these characters, resulting in unchanged behaviour. I used
something like:

reason = u'%s'.encode('utf-8') % reason
reason = unicode(reason, 'utf-8')

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Julian Foad wrote:
> Branko Čibej wrote:
>   
>> Bhuvaneswaran A wrote:
>>     
>>> The failure message for few tests contain special characters, ex:
>>>       
>
> What do you mean by "special" characters? Unprintable characters?
> Non-UTF8 characters? Invalid XML characters? Characters that are XML
> syntax characters such as "<"?
>   

He's filtering out characters that are invalid in XML -- that's all the
ASCII control codes except CR and LF. There is no way to represent or
quote those characters in valid XML, you can't even use character
references.

-- Brane

Re: [PATCH] Handle special characters in Junit report

Posted by Julian Foad <ju...@wandisco.com>.
Branko Čibej wrote:
> Bhuvaneswaran A wrote:
> > The failure message for few tests contain special characters, ex:

What do you mean by "special" characters? Unprintable characters?
Non-UTF8 characters? Invalid XML characters? Characters that are XML
syntax characters such as "<"?

> > prop_tests.py. As a result, it creates an invalid xml file and not being
> > displayed in Hudson.
> >
> > This commit fixes this issue, also tracked in issue 3541. With this fix,
> > the test results are displayed in Hudson, especially the results
> > specific to 1.6.x solaris build.
> >   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
> >   
> > Index: tools/dev/gen_junit_report.py
> > =======================================
> > --- tools/dev/gen_junit_report.py	(revision 886204)
> > +++ tools/dev/gen_junit_report.py	(working copy)
> > @@ -46,6 +46,16 @@
> > data = data.replace(char, encode[char])
> > return data
> > +def remove_special_characters(data):
> > + """remove special characters in test failure reasons"""
> > + if not data:
> > + return data
> > + chars_table = "".join([chr(n) for n in xrange(256)])
> > + # remove all special characters upto ascii value 31, except line
> > feed (10)
> > + # and carriage return (13)
> > + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> > chars_table[14:31]

Isn't the indexing off by one? Should be [0:10] ... [11:13] ... [14:32].

> > + return data.translate(chars_table, chars_to_remove)
> 
> You want to rebuild the table every single time? Be serious.

/me translates that to, "Although this is only a test result logging
application, it would please my aesthetic sensibilities if it were more
efficient by building the table only once." :-)

> Also, wouldn't it be more proper to find out why the tests put control
> characters in the failure description than to just blindly throw them away?

Or just escape the "special" characters.

> > +
> > def start_junit():
> > """define the beginning of xml document"""
> > head = """<?xml version="1.0" encoding="UTF-8"?>"""
> > @@ -72,6 +82,7 @@
> > """mark the test case as FAILED"""
> > casename = xml_encode(casename)
> > sub_test_name = test_name.replace('.', '-')
> > + reason = remove_special_characters(reason)
> > case = """<testcase time="ELAPSED_CASE_%s" name="%s" classname="%s">
> > <failure type="Failed"><![CDATA[%s]]></failure>
> > </testcase>""" % (test_name, casename, sub_test_name, reason)
> 
> Oh yeah. I'm going to write a test that fails and the reason will be
> "]]>", how would you like that? :)

This page:
<http://www.lshift.net/blog/2007/10/25/xml-cdata-and-escaping> gives a
simple trick to "escape" a string before putting it in a CDATA section:

  replace every occurrence of "]]>" with "]]]]><![CDATA[>".

But... this is only a test result logging application. If it works with
what the Subversion test suite produces, then it works.

- Julian


Re: [PATCH] Handle special characters in Junit report

Posted by Bhuvaneswaran A <bh...@collab.net>.
On Fri, 2009-12-04 at 10:37 +0100, Branko Čibej wrote:
> Bhuvaneswaran A wrote:
> > The failure message for few tests contain special characters, ex:
> > prop_tests.py. As a result, it creates an invalid xml file and not being
> > displayed in Hudson.
> >
> > This commit fixes this issue, also tracked in issue 3541. With this fix,
> > the test results are displayed in Hudson, especially the results
> > specific to 1.6.x solaris build.
> >   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
> >   
> > Index: tools/dev/gen_junit_report.py
> > =======================================
> > --- tools/dev/gen_junit_report.py	(revision 886204)
> > +++ tools/dev/gen_junit_report.py	(working copy)
> > @@ -46,6 +46,16 @@
> > data = data.replace(char, encode[char])
> > return data
> > +def remove_special_characters(data):
> > + """remove special characters in test failure reasons"""
> > + if not data:
> > + return data
> > + chars_table = "".join([chr(n) for n in xrange(256)])
> > + # remove all special characters upto ascii value 31, except line
> > feed (10)
> > + # and carriage return (13)
> > + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> > chars_table[14:31]
> > + return data.translate(chars_table, chars_to_remove)
> 
> You want to rebuild the table every single time? Be serious.

This is just a string of length 256, being created for every failure
message. Even if all tests (73) fail, this string is going to be created
73 times, and only!

> Also, wouldn't it be more proper to find out why the tests put control
> characters in the failure description than to just blindly throw them away?

To identify the reason why the failure message is one thing. This is
prop_tests.py. Refer to the attachment in the issue 3541 for details.

Even if there are control characters in failure message, the valid junit
file should be generated and shouldn't refuse to generate test result. 

> > def start_junit():
> > """define the beginning of xml document"""
> > head = """<?xml version="1.0" encoding="UTF-8"?>"""
> > @@ -72,6 +82,7 @@
> > """mark the test case as FAILED"""
> > casename = xml_encode(casename)
> > sub_test_name = test_name.replace('.', '-')
> > + reason = remove_special_characters(reason)
> > case = """<testcase time="ELAPSED_CASE_%s" name="%s" classname="%s">
> > <failure type="Failed"><![CDATA[%s]]></failure>
> > </testcase>""" % (test_name, casename, sub_test_name, reason)
> 
> Oh yeah. I'm going to write a test that fails and the reason will be
> "]]>", how would you like that? :)

I'll handle the following feedback:
  a) Define the table globally (once) and re-use it.
  b) Handle "]]>" in failure message.

-- 
Bhuvaneswaran A    
CollabNet Software P Ltd.  |  www.collab.net

Re: [PATCH] Handle special characters in Junit report

Posted by Branko Čibej <br...@xbc.nu>.
Bhuvaneswaran A wrote:
> The failure message for few tests contain special characters, ex:
> prop_tests.py. As a result, it creates an invalid xml file and not being
> displayed in Hudson.
>
> This commit fixes this issue, also tracked in issue 3541. With this fix,
> the test results are displayed in Hudson, especially the results
> specific to 1.6.x solaris build.
>   http://subversion.tigris.org/issues/show_bug.cgi?id=3541
>   
> Index: tools/dev/gen_junit_report.py
> =======================================
> --- tools/dev/gen_junit_report.py	(revision 886204)
> +++ tools/dev/gen_junit_report.py	(working copy)
> @@ -46,6 +46,16 @@
> data = data.replace(char, encode[char])
> return data
> +def remove_special_characters(data):
> + """remove special characters in test failure reasons"""
> + if not data:
> + return data
> + chars_table = "".join([chr(n) for n in xrange(256)])
> + # remove all special characters upto ascii value 31, except line
> feed (10)
> + # and carriage return (13)
> + chars_to_remove = chars_table[0:9] + chars_table[11:12] +
> chars_table[14:31]
> + return data.translate(chars_table, chars_to_remove)

You want to rebuild the table every single time? Be serious.
Also, wouldn't it be more proper to find out why the tests put control
characters in the failure description than to just blindly throw them away?

> +
> def start_junit():
> """define the beginning of xml document"""
> head = """<?xml version="1.0" encoding="UTF-8"?>"""
> @@ -72,6 +82,7 @@
> """mark the test case as FAILED"""
> casename = xml_encode(casename)
> sub_test_name = test_name.replace('.', '-')
> + reason = remove_special_characters(reason)
> case = """<testcase time="ELAPSED_CASE_%s" name="%s" classname="%s">
> <failure type="Failed"><![CDATA[%s]]></failure>
> </testcase>""" % (test_name, casename, sub_test_name, reason)

Oh yeah. I'm going to write a test that fails and the reason will be
"]]>", how would you like that? :)

-- Brane