xmlsec / python-xmlsec

Python bindings for the XML Security Library.
MIT License
95 stars 99 forks source link

Use lxml's adoptExternalDocument() #239

Open scoder opened 2 years ago

scoder commented 2 years ago

It seems that xmlsec's lxml integration does not call adoptExternalDocument() to create an lxml wrapper for an internally created libxml2 XML tree. If it wants to pass externally created XML documents into lxml, then it should call it. Simply wrapping an arbitrary libxml2 tree in an lxml Element violates lxml's tree invariants, such as shared usage of an XML name dict. This can lead to misbehaving elements, such as missing results from .find() (see https://bugs.launchpad.net/lxml/+bug/1960668).

https://github.com/lxml/lxml/blob/95f8006336889df154c45130db1ec897b424e529/src/lxml/includes/etreepublic.pxd#L64-L65

I admit that this is probably un(der)documented, so not your fault.