You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2026/08/17 08:37:19 UTC

(maven) branch maven-3.10.x updated: feat: add relativePath validation (#12742)

This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch maven-3.10.x
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/maven-3.10.x by this push:
     new 70ed0e27be feat: add relativePath validation (#12742)
70ed0e27be is described below

commit 70ed0e27be20399cc1ae5b2e48a283e426445090
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Mon Aug 17 10:37:13 2026 +0200

    feat: add relativePath validation (#12742)
    
    As it seems no Maven 3.x version did validate it. Validation fails
    if project being built (uses strict validation), while dependencies
    are not failing (uses minimal validation).
---
 .../model/validation/DefaultModelValidator.java    | 19 +++++++++++
 .../validation/DefaultModelValidatorTest.java      | 16 ++++++++++
 .../raw-model/bad-parent-relativePath1.xml         | 37 ++++++++++++++++++++++
 .../raw-model/ok-parent-relativePath1.xml          | 37 ++++++++++++++++++++++
 4 files changed, 109 insertions(+)

diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
index 373c371c5a..6cfed06ec7 100644
--- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java
@@ -80,8 +80,12 @@ public class DefaultModelValidator implements ModelValidator {
     private static final Pattern CI_FRIENDLY_EXPRESSION = Pattern.compile("\\$\\{(.+?)}");
     private static final Pattern EXPRESSION_PROJECT_NAME_PATTERN = Pattern.compile("\\$\\{(project.+?)}");
 
+    // see below; multiple fields depend on this field
     private static final String ILLEGAL_FS_CHARS = "\\/:\"<>|?*";
 
+    private static final String ILLEGAL_RELATIVE_PATH_FS_CHARS =
+            ILLEGAL_FS_CHARS.replace("\\", "").replace("/", "");
+
     private static final String ILLEGAL_VERSION_CHARS = ILLEGAL_FS_CHARS;
 
     private static final String ILLEGAL_REPO_ID_CHARS = ILLEGAL_FS_CHARS;
@@ -153,6 +157,21 @@ public void validateRawModel(Model m, ModelBuildingRequest request, ModelProblem
         } else if (request.getValidationLevel() >= ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0) {
             Severity errOn30 = getSeverity(request, ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_3_0);
 
+            if (parent != null
+                    && parent.getRelativePath() != null
+                    && !parent.getRelativePath().isEmpty()) {
+                validateBannedCharacters(
+                        "parent.",
+                        "relativePath",
+                        problems,
+                        errOn30,
+                        Version.BASE,
+                        parent.getRelativePath(),
+                        null,
+                        parent,
+                        ILLEGAL_RELATIVE_PATH_FS_CHARS);
+            }
+
             // [MNG-6074] Maven should produce an error if no model version has been set in a POM file used to build an
             // effective model.
             //
diff --git a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
index e9535431c4..b2912a17dd 100644
--- a/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
+++ b/maven-model-builder/src/test/java/org/apache/maven/model/validation/DefaultModelValidatorTest.java
@@ -890,4 +890,20 @@ public void testMinimalWithoutParent() throws Exception {
         SimpleProblemCollector result = validateRaw("raw-model/minimal-without-parent.xml");
         assertViolations(result, 0, 0, 0);
     }
+
+    @Test
+    public void testBadParentRelativePath1() throws Exception {
+        SimpleProblemCollector result = validateRaw("raw-model/bad-parent-relativePath1.xml");
+        assertViolations(result, 0, 1, 0);
+
+        assertEquals(
+                "'parent.relativePath' must not contain any of these characters :\"<>|?* but found :",
+                result.getErrors().get(0));
+    }
+
+    @Test
+    public void testOkParentRelativePath1() throws Exception {
+        SimpleProblemCollector result = validateRaw("raw-model/ok-parent-relativePath1.xml");
+        assertViolations(result, 0, 0, 0);
+    }
 }
diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-relativePath1.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-relativePath1.xml
new file mode 100644
index 0000000000..1d59ec3ec0
--- /dev/null
+++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/bad-parent-relativePath1.xml
@@ -0,0 +1,37 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>com.example.group</groupId>
+		<artifactId>com-parent</artifactId>
+		<version>1.0</version>
+		<relativePath>g:a:v</relativePath>
+	</parent>
+	<groupId>com.example.group</groupId>
+	<artifactId>invalid-relative-path</artifactId>
+	<version>1.0</version>
+
+	<description>
+		This will test if the validation for the parent relativePath
+		is working correct in case of illegal characters
+	</description>
+</project>
diff --git a/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-parent-relativePath1.xml b/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-parent-relativePath1.xml
new file mode 100644
index 0000000000..457de7c926
--- /dev/null
+++ b/maven-model-builder/src/test/resources/poms/validation/raw-model/ok-parent-relativePath1.xml
@@ -0,0 +1,37 @@
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>com.example.group</groupId>
+		<artifactId>com-parent</artifactId>
+		<version>1.0</version>
+		<relativePath>a\b</relativePath>
+	</parent>
+	<groupId>com.example.group</groupId>
+	<artifactId>valid-relative-path</artifactId>
+	<version>1.0</version>
+
+	<description>
+		This will test if the validation for the parent relativePath
+		is working correct in case of file separators
+	</description>
+</project>