Skip Menu |

This queue is for tickets about the XML-Twig CPAN distribution.

Report information
The Basics
Id: 14959
Status: resolved
Priority: 0/
Queue: XML-Twig

People
Owner: Nobody in particular
Requestors: tom@eborcom.com (no email address)
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 3.21
Fixed in: 3.22

Attachments


Subject: wrap_children fails with escaped characters in attributes
XML::Twig's wrap_children method does not cope properly with escaping in attribute values. Please run the attached script. It wraps elements where type="this" in a <type> correctly but fails to wrap elements where type="t&amp;hat": <entries> <type id="twig_id_0001" name="this"> <entry id="1" type="this"/> <entry id="2" type="this"/> </type> <entry id="3" type="t&amp;hat"/> </entries> If you remove the &amp; and instead have type="that" it works as expected and wraps both types in new elements: <entries> <type id="twig_id_0001" name="this"> <entry id="1" type="this"/> <entry id="2" type="this"/> </type> <type name="that"> <entry id="3" type="that"/> </type> </entries> Thanks for all the work you put into XML::Twig - it's a really useful module. Tom
Download twig_experiment
application/octet-stream 551b

Message body not shown because it is not plain text.

[guest - Thu Oct 6 07:31:03 2005]: Show quoted text
> XML::Twig's wrap_children method does not cope properly with escaping > in attribute values. > > Please run the attached script. It wraps elements where type="this" > in a <type> correctly but fails to wrap elements where > type="t&amp;hat":
Hi Tom, First in the attached script, you wrap entries with a type of 'that', but the entry has an attribute of 't&amp;hat'. So it should not (and is not) wrapped. If I replace 'that' by 't&amp;hat', then entry 3 is wrapped, but the name attribute is set to 't&amp;amp;hat'. Here is the problem: in wrap_children, in the optional_value for the attribute (the 'this' or 'that' in your example) ", < and & should be xml-escaped ('t&amp;hat'). Otherwise it can becomes impossible for XML::Twig to parse the "tag". But then, in the attribute hashref, the values should _not_ be xml-escaped, as usual when you set attributes. In short you have to either loop on 'that' and xml-escape it before using it in the "regexp", or loop on 't&amp;hat' and... de-escape it before using it. Sorry for the loss of elegance in the solution ;--( Does this help? BTW, I have took this opportunity to improve the docs for wrap_children (http://www.xmltwig.com/xmltwig/twig_dev.html#METHODS_XML_Twig_Elt_wrap_children) , are they more helpful now (and congratulations for managing to use the method with the previous docs!)? Thanks __ mirod
[tom@eborcom.com - Fri Oct 7 09:37:42 2005]: Show quoted text
> I've re-thought the problem and attached another script > that I think (and hope!) demonstrates a bug. The script wraps each > <type> in a <types> when I would expect it to wrap them both in one. > > The important part is line 23. If I remove the '>>' everything > behaves as expected.
Yes, this is a bug. The decision I made a long time ago not to escape '>' unless I have to still comes back to haunt me ;--( The version on my web site should be OK. __ mirod