Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: defaultNamespace detection fails on XML-attributes when deserializing #11

Closed
jkowalleck opened this issue Sep 22, 2023 · 1 comment · Fixed by #20
Closed

bug: defaultNamespace detection fails on XML-attributes when deserializing #11

jkowalleck opened this issue Sep 22, 2023 · 1 comment · Fixed by #20
Assignees
Labels
bug Something isn't working

Comments

@jkowalleck
Copy link
Collaborator

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)

@jkowalleck
Copy link
Collaborator Author

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]

@jkowalleck jkowalleck added the bug Something isn't working label Sep 27, 2023
@jkowalleck jkowalleck self-assigned this Sep 27, 2023
jkowalleck added a commit that referenced this issue Sep 28, 2023
fixes #11

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleck jkowalleck changed the title bug: defaultNamesspace detection fails on XML-attributes when deserializing bug: defaultNamespace detection fails on XML-attributes when deserializing Oct 1, 2023
jkowalleck added a commit that referenced this issue Oct 1, 2023
* fixes:  serialization with defaultNS fails [#12](#12)
* fixes: defaultNamespace detection fails on XML-attributes when deserializing [#11](#11)

---------

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant