[lxml-dev] Bug with attribute mangling when adding child elements

Hello, I noticed today that certain child attribute values are mangled when you try to insert/append child elements onto parent elements. I have written a test script for this as usual. I'm probably missing something... again. :) Thanks, Noah -- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hello, I have just noticed that if you set the attributes after you have added to the tree the weird bug does not happen. Attached is a modified version of the file. Hope this helps someone.... Noah On 29/05/06, Noah Slater <nslater@gmail.com> wrote:
-- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hi Noah, Noah Slater wrote:
Thanks for reporting this. It looks like a bug in libxml2, as it only happens for "xml:id", not for other attributes. I guess the bug is in xmlReconciliateNs, but that's really just guessing. A simpler way to reproduce this is: ------------------------------- root = etree.Element('element') subelement = etree.Element('subelement') subelement.set("{http://www.w3.org/XML/1998/namespace}id", "foo") root.append(subelement) print etree.tostring(root) ------------------------------- What surprises me most is that ElementTree (1.2.6) has a similar bug. It returns this for subelement.attrib after appending: {'{}id': 'foo'} I'll file a bug report on libxml2 anyway. Stefan

Varified using python-elementtree v.1.2.6-8 on Debian PPC (Sid):
On 29/05/06, Fredrik Lundh <fredrik@pythonware.com> wrote:
-- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hi Fredrik, sorry for the confusion. Fredrik Lundh wrote:
I get that, too. I had forgotten a tiny 'self.' in the test case, which let it use etree instead of ElementTree. Oh well, imports ... Sorry, Stefan

Hi, Stefan Behnel wrote:
Well, it was /related/ to xmlReconciliateNs, but not a bug in libxml2 and only by chance it showed fro xml:id. lxml was running xmlReconciliateNs /after/ cleaning up the document references in the Python elements. Which means it freed the document if all references were gone, but before trying to access its namespaces. Great. That bug was in there for ages, since SVN revision 12568! Fixed in the trunk. Stefan

Hello, I have just noticed that if you set the attributes after you have added to the tree the weird bug does not happen. Attached is a modified version of the file. Hope this helps someone.... Noah On 29/05/06, Noah Slater <nslater@gmail.com> wrote:
-- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hi Noah, Noah Slater wrote:
Thanks for reporting this. It looks like a bug in libxml2, as it only happens for "xml:id", not for other attributes. I guess the bug is in xmlReconciliateNs, but that's really just guessing. A simpler way to reproduce this is: ------------------------------- root = etree.Element('element') subelement = etree.Element('subelement') subelement.set("{http://www.w3.org/XML/1998/namespace}id", "foo") root.append(subelement) print etree.tostring(root) ------------------------------- What surprises me most is that ElementTree (1.2.6) has a similar bug. It returns this for subelement.attrib after appending: {'{}id': 'foo'} I'll file a bug report on libxml2 anyway. Stefan

Varified using python-elementtree v.1.2.6-8 on Debian PPC (Sid):
On 29/05/06, Fredrik Lundh <fredrik@pythonware.com> wrote:
-- "Creativity can be a social contribution, but only in so far as society is free to use the results." - R. Stallman

Hi Fredrik, sorry for the confusion. Fredrik Lundh wrote:
I get that, too. I had forgotten a tiny 'self.' in the test case, which let it use etree instead of ElementTree. Oh well, imports ... Sorry, Stefan

Hi, Stefan Behnel wrote:
Well, it was /related/ to xmlReconciliateNs, but not a bug in libxml2 and only by chance it showed fro xml:id. lxml was running xmlReconciliateNs /after/ cleaning up the document references in the Python elements. Which means it freed the document if all references were gone, but before trying to access its namespaces. Great. That bug was in there for ages, since SVN revision 12568! Fixed in the trunk. Stefan
participants (3)
-
Fredrik Lundh
-
Noah Slater
-
Stefan Behnel