madpah / serializable

Pythonic library to aid with serialisation and deserialisation to/from JSON and XML.

Home Page:https://py-serializable.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: defaultNamespace detection fails on XML-attributes when deserializing

jkowalleck opened this issue · comments

and this one was completely unable to detect the defaultNS, and assumed it was '' -- which is the identifier for the defaultNS not the defaultNS itself ...
and then the NameSpace-detection on XML-attributes fails ...

see CycloneDX/cyclonedx-python-lib#438 (comment)

working patch:

if default_namespace is None:
_namespaces = dict([node for _, node in
SafeElementTree.iterparse(StringIO(SafeElementTree.tostring(data, 'unicode')),
events=['start-ns'])])
if 'ns0' in _namespaces:
default_namespace = _namespaces['ns0']
else:
default_namespace = ''

      if default_namespace is None:
          _namespaces = dict([node for _, node in
                              SafeElementTree.iterparse(StringIO(SafeElementTree.tostring(data, 'unicode')),
                                                        events=['start-ns'])])
-         if 'ns0' in _namespaces:
-             default_namespace = _namespaces['ns0']
-         else:
-             default_namespace = ''
+         default_namespace = (re.compile(r'^\{(.+?)\}.').search(data.tag) or (None,_namespaces.get('')))[1]