gnodet opened a new pull request, #11823: URL: https://github.com/apache/maven/pull/11823
## Summary - When a POM uses a namespace prefix mapping to the same URI as the element's default namespace (e.g., `xmlns:mvn="http://maven.apache.org/POM/4.0.0"`), prefixed attributes like `mvn:combine.children` are now normalized to their unprefixed form (`combine.children`) at read time - Redundant `xmlns:prefix` declarations are removed - The write side now properly handles namespace declarations (`xmlns:prefix`) and prefixed attributes for foreign namespaces Fixes #11760 ## Problem The [jdbi project](https://github.com/apache/maven/issues/11760) uses `mvn:combine.children="append"` with `xmlns:mvn="http://maven.apache.org/POM/4.0.0"` to combine compiler arguments. This caused two bugs: 1. **Merge directives silently ignored**: The merge logic in `DefaultXmlService` looks up `combine.children` (unprefixed), so `mvn:combine.children` was never found and the append directive was ignored 2. **Invalid consumer POM**: The consumer POM transformation dropped the `xmlns:mvn` declaration but kept the prefixed attributes, producing invalid XML that couldn't be parsed by downstream consumers ## Fix **Read side** (`DefaultXmlService.doBuild()`): - When an attribute's namespace URI matches the element's default namespace, strip the prefix (since `mvn:combine.children` and `combine.children` are semantically identical in the same namespace) - Remove `xmlns:prefix` declarations that are redundant with the element's default namespace **Write side** (`DefaultXmlService.writeNode()`): - `xmlns:prefix` attributes are written as proper namespace declarations via `writeNamespace()` - Prefixed attributes with a matching `xmlns:` declaration are written with the correct namespace URI - `xml:` prefixed attributes use the XML namespace URI ## Test plan - [x] `testNamespacePrefixNormalization` — `mvn:combine.children` normalized to `combine.children`, `xmlns:mvn` removed - [x] `testPrefixedCombineChildrenMerge` — `mvn:combine.children="append"` works correctly in merge - [x] `testPrefixedCombineSelfMerge` — `mvn:combine.self="override"` works correctly in merge - [x] `testForeignNamespacePrefixPreserved` — different namespace prefix (`custom:`) is preserved - [x] `testXmlSpacePreservedAfterNormalization` — `xml:space="preserve"` unaffected - [x] `testNestedNamespacePrefixNormalization` — works in deeply nested elements - [x] `testWriteWithNamespaceAttributes` — foreign namespace attributes round-trip correctly - [x] `testNormalizedRoundTrip` — no `xmlns:mvn` or `mvn:` prefix in output after normalization - [x] All existing tests pass (43 tests in maven-xml, full downstream build clean) 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
