Skip to content

Fix keep xs ns prefixes - #335

Merged
theseal merged 5 commits into
masterfrom
fix-keep-xs-ns-prefixes
Sep 8, 2026
Merged

Fix keep xs ns prefixes#335
theseal merged 5 commits into
masterfrom
fix-keep-xs-ns-prefixes

Conversation

@theseal

@theseal theseal commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

@vladimir-mencl-eresearch commits where unsigned and I was not allowed to write in the incoming branch so had to do this branch dance. 🤷‍♂️

Also added test to check for the "default" NSes.

Closes #333 and #334

Fixes #333

The lxml.etree.cleanup_namespaces function only considers namespaces used
in XML Element and Attribute names, but not in attribute values.
The xs namespaces is used only in values of xsi:type attributes
and is thus not considered as used by LXML - and would get removed.

Keep it explicitly to avoid creating invalid metadata.

Co-authored-by: Johan Wassberg <jocar@sunet.se>
The namespace cleanup was being ignored for MDQ
per-entity publication - it did nothing when
invoked on element other than the root element.

It would also be resource intensive to clean up
when publishing each individual element.

Clean up instead at the source - and there,
the guard condition is no longer required
(the working document is always XML)

Co-authored-by: Johan Wassberg <jocar@sunet.se>
@theseal
theseal requested a review from btmattsson September 4, 2026 08:41
Comment thread src/pyff/samlmd.py Outdated
Instead of a hardcorded list of known Qname defines
@theseal

theseal commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

@vladimir-mencl-eresearch Can you try this branch out before we do a merge?

@vladimir-mencl-eresearch

Copy link
Copy Markdown
Contributor

Thanks @btmattsson - good catch, I was taking a short-cut here for commonly used namespace prefixes - but it's not guaranteed that exactly these prefixes would be used. (And some tooling could possibly normalise/rename prefixes...)

Thanks for this extra work @theseal - and sorry, I missed signing my commits (will remember for this project for the future) - and I should have allowed you access to the branch (will remember as well).

I've just tested this in my (DEV) env and it works exactly as expected (and also supports the case when the XML schema namespaces are mapped to a different prefix).

PS:
When I saw Björn's message, I first thought of solving it by looking the namespaces (http://www.w3.org/2001/XMLSchema, http://www.w3.org/2001/XMLSchema-instance) up in nsmap and getting the prefixes they are mapped to (if used) from there.

Your approach is even more generic, supporting also other namespace-scoped attribute values. And is the best we can do without parsing/interpreting the full schema to see which attributes actually declares their values as using namespaces (declaring its type as xs:QName). However, combining the regexp with checking what is actually a mapped prefix makes it safe - and the only risk (in a very stretched hypothetical case) is keeping a prefix that we theoretically should have discarded.

Thumbs-up from me to merge this.

@theseal
theseal requested a review from btmattsson September 7, 2026 18:08
Both should be found by qname_prefixes() if they are in use
@vladimir-mencl-eresearch

Copy link
Copy Markdown
Contributor

Thumbs up for the latest change - yes, if we are searching for qname values, we no longer need to explicitly whitelist xs or xsi, anything in use will now get found. (Elemenent + attribute name use directly by cleanup_namespaces, and attribute values by qname_prefixes)

@btmattsson

Copy link
Copy Markdown

Looks good
LGTM

@theseal
theseal merged commit 5d45efb into master Sep 8, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: cleanup_namespaces removes also xs + xsi prefixes

3 participants