[maven-4.0.x] Fix consumer POM serialization of prefixed XML attributes (fixes #11760)#12110
Merged
Conversation
During consumer POM transformation, namespace declarations like xmlns:mvn on <project> are lost (not part of the Maven model), but prefixed attributes like mvn:combine.children on XmlNode configuration trees survive, producing invalid XML with undeclared namespace prefixes. Fix by adding namespace context tracking to XmlNode: the parser now accumulates namespace declarations and propagates them to child nodes. The StAX and XPP3 writers resolve prefixed attributes against local declarations first, then the inherited namespace context, auto-declaring namespaces as needed. Orphaned prefixes (no declaration, no context) are stripped as a last resort to ensure valid XML output. Changes: - Add XmlNode.namespaces() returning inherited prefix-to-URI bindings - Accumulate and propagate namespace context during parsing in DefaultXmlService - Fix writer-stax.vm and writer.vm to resolve and declare namespaces properly - Preserve dominant node's namespace context during merge - Add 28 tests covering parsing, writing, merging, and consumer POM simulation
…eStrategyTest Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@gnodet Please assign appropriate label to PR according to the type of change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backport of #11823 to maven-4.0.x.
Fix consumer POM serialization so that prefixed attributes (like
mvn:combine.children) produce valid XML even when the namespace declaration (xmlns:mvn) was on an ancestor element not part of the Maven model.Fixes #11760
Changes
XmlNode.namespaces()returning inherited prefix-to-URI bindingsDefaultXmlServicewriter-stax.vmandwriter.vmto resolve and declare namespaces properlyClaude Code on behalf of Guillaume Nodet