gnodet-bot commented on code in PR #14033:
URL: https://github.com/apache/maven/pull/14033#discussion_r4595828605
##########
impl/maven-support/src/test/java/org/apache/maven/model/v4/MavenStaxReaderTest.java:
##########
@@ -281,6 +283,70 @@ void testLocationReportingForListElements() throws
Exception {
assertEquals(5, module3Location.getColumnNumber(), "Module 3 should
start at column 5");
}
+ @Test
+ void testRandomRootNamespaceIsRejectedInStrictMode() {
+ // https://github.com/apache/maven/issues/10985
+ String xml = pomWithNamespace("https://ff.com");
+
+ XMLStreamException ex = assertThrows(XMLStreamException.class, () ->
fromXml(xml));
+ assertTrue(
+ ex.getMessage().contains("Unrecognized namespace
'https://ff.com' for root element 'project'"),
+ ex.getMessage());
+
assertTrue(ex.getMessage().contains("http://maven.apache.org/POM/4.0.0"),
ex.getMessage());
+ assertNotNull(ex.getLocation());
+ assertEquals(1, ex.getLocation().getLineNumber());
+ }
+
+ @ParameterizedTest
+ // only exact matches are accepted, no prefix matching
+ @ValueSource(
+ strings = {
+ "http://maven.apache.org/POM/",
+ "http://maven.apache.org/POM/4.0",
+ "http://maven.apache.org/POM/4.0.0/",
+ "http://maven.apache.org/POM/9.9.9",
+ // namespaces are case-sensitive and the scheme is part of the
namespace name
+ "https://maven.apache.org/POM/4.0.0",
+ "http://maven.apache.org/pom/4.0.0",
+ // namespaces of other Maven models are not valid for a POM
+ "http://maven.apache.org/METADATA/1.1.0",
+ "http://maven.apache.org/SETTINGS/1.0.0"
+ })
+ void testUnknownRootNamespacesAreRejectedInStrictMode(String ns) {
+ XMLStreamException ex = assertThrows(XMLStreamException.class, () ->
fromXml(pomWithNamespace(ns)), ns);
+ assertTrue(ex.getMessage().contains("Unrecognized namespace '" + ns +
"'"), ex.getMessage());
+ }
+
+ @ParameterizedTest
+ @ValueSource(
+ strings = {
+ "http://maven.apache.org/POM/4.0.0",
+ "http://maven.apache.org/POM/4.1.0",
+ "http://maven.apache.org/POM/4.2.0"
+ })
+ void testKnownRootNamespacesAreAcceptedInStrictMode(String ns) throws
XMLStreamException {
Review Comment:
⚠️ **Branch mismatch — `4.2.0` is not an accepted namespace on
`maven-4.0.x`.**
On this branch, the modello config is `<version>4.1.0</version>` with
`minimalVersion=4.0.0`, so the template generates:
```java
private static final List<String> ALLOWED_NAMESPACES = List.of(
"http://maven.apache.org/POM/4.0.0",
"http://maven.apache.org/POM/4.1.0");
```
The `4.2.0` namespace only exists on `master` (where
`<version>4.2.0</version>`). This test case was not adapted during backport and
will fail with `XMLStreamException: Unrecognized namespace '...POM/4.2.0'`.
```suggestion
@ValueSource(
strings = {
"http://maven.apache.org/POM/4.0.0",
"http://maven.apache.org/POM/4.1.0"
})
```
--
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]