fix(maven): match declarations in the project namespace (#12672)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 01:54:59 +00:00
1 parent 070d6420ec
commit 0ab693fe81
4 files changed
+27 -15

No files matched your search

+5 -5
View File
@@ -623,11 +623,11 @@ it("refuses a document type declaration", () => {
);
});
it("refuses XML that is not a Maven project", () => {
expectFailure(
"<module><artifactId>demo</artifactId></module>",
"unsupported",
);
it.each([
"<module><artifactId>demo</artifactId></module>",
'<project xmlns:ext="urn:example"><ext:artifactId>demo</ext:artifactId></project>',
])("refuses XML that is not a Maven project: %s", (source) => {
expectFailure(source, "unsupported");
});
it("refuses a POM with two top-level dependencies blocks", () => {
+8 -6
View File
@@ -49,8 +49,13 @@ const childElements = (element: Element): Element[] => {
return children;
};
const childrenNamed = (element: Element, local: string): Element[] =>
childElements(element).filter((child) => child.localName === local);
const childrenNamed = (element: Element, ...names: string[]): Element[] =>
childElements(element).filter(
(child) =>
(child.namespaceURI ?? "") === (element.namespaceURI ?? "") &&
child.localName !== null &&
names.includes(child.localName),
);
const soleNamed = (element: Element, local: string): Element | undefined => {
const matches = childrenNamed(element, local);
@@ -73,10 +78,7 @@ const isMavenProjectRoot = (root: Node | null): root is Element => {
if (root.namespaceURI === MAVEN_POM_NAMESPACE) return true;
return (
(root.namespaceURI === null || root.namespaceURI === "") &&
childElements(root).some(
(child) =>
child.localName === "modelVersion" || child.localName === "artifactId",
)
childrenNamed(root, "modelVersion", "artifactId").length > 0
);
};