This is an automated email from the ASF dual-hosted git repository.
gnodet 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 12ce19b721 [ISSUE-10329] Document behaviour of UrlNormalizer (#12294)
12ce19b721 is described below
commit 12ce19b7212ac8c37f8b57f549ca88018512fafb
Author: Guillaume Nodet <[email protected]>
AuthorDate: Wed Jun 17 16:19:24 2026 +0200
[ISSUE-10329] Document behaviour of UrlNormalizer (#12294)
Add detailed Javadoc to UrlNormalizer interface explaining its
string-based URL normalization behavior, and add additional test cases
for DefaultUrlNormalizer covering relative path traversals, encoded
spaces, and malformed URLs.
Backport of #12293
Co-authored-by: Giovanni van der Schelde <[email protected]>
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../java/org/apache/maven/model/path/UrlNormalizer.java | 10 ++++++++--
.../maven/model/path/DefaultUrlNormalizerTest.java | 16 ++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git
a/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
b/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
index 73be60dc44..2ffeb6d4cb 100644
---
a/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
+++
b/maven-model-builder/src/main/java/org/apache/maven/model/path/UrlNormalizer.java
@@ -19,8 +19,14 @@
package org.apache.maven.model.path;
/**
- * Normalizes a URL to remove the ugly parent references "../" that got
potentially inserted by URL adjustment during
- * model inheritance.
+ * Simplifies URLs by removing parent directory references ("/../") and
collapsing path segments.
+ * This performs purely string-based normalization without full URL parsing or
validation.
+ *
+ * <p>The normalization process iteratively removes "/../" segments by
eliminating the preceding path segment,
+ * effectively resolving relative path traversals.
+ *
+ * <p>This does not guarantee that the resulting URL is valid or reachable; it
simply
+ * produces a more canonical representation of the input string.
*
* @author Benjamin Bentmann
*/
diff --git
a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
index def334d469..b2d55a7e4f 100644
---
a/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
+++
b/maven-model-builder/src/test/java/org/apache/maven/model/path/DefaultUrlNormalizerTest.java
@@ -78,4 +78,20 @@ public void parentDirectoryRemovedFromRelativeUriReference()
{
public void leadingParentDirectoryNotRemovedFromRelativeUriReference() {
assertEquals("../", normalize("../"));
}
+
+ @Test
+ public void testMultipleParentRefsInRelativePath() {
+ assertEquals("b", normalize("a/../b"));
+ assertEquals("b/d", normalize("a/../b/c/../d"));
+ assertEquals("b/c/d", normalize("a/../b/c/d"));
+ assertEquals("b/c", normalize("a/../b/c"));
+ assertEquals("b/", normalize("a/../b/c/../"));
+ }
+
+ @Test
+ public void testPreservationOfEncodedAndMalformedUrls() {
+ assertEquals("https://example.com/a%20b/c%20d",
normalize("https://example.com/a%20b/c%20d"));
+ assertEquals("https://example.com/a b/c d",
normalize("https://example.com/a b/c d"));
+ assertEquals("ht!tps:/bad_url", normalize("ht!tps:/bad_url"));
+ }
}