This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch button-starfish in repository https://gitbox.apache.org/repos/asf/maven.git
commit 3e64569a35e1c5b2bf4764ab1a3cf7bfa2310cd3 Author: Giovanni van der Schelde <[email protected]> AuthorDate: Wed Jun 17 15:34:04 2026 +0200 [ISSUE-10329] Document behaviour of UrlNormalizer 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: 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")); + } }
