elharo commented on code in PR #287:
URL:
https://github.com/apache/maven-remote-resources-plugin/pull/287#discussion_r4229940612
##########
src/main/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssembler.java:
##########
@@ -568,33 +567,40 @@ protected String appendPath(String parentPath, String
childPath, String pathAdju
uncleanPath = uncleanPath.substring(protocolIdx + 3);
}
- if (uncleanPath.startsWith("/")) {
- cleanedPath += "/";
- }
-
return cleanedPath + resolvePath(uncleanPath);
}
- // TODO Move this to plexus-utils' PathTool.
+ /**
+ * Normalizes the path part of an SCM URL using pure string manipulation,
independent of the
+ * host file system rules. This matters because SCM URLs routinely contain
characters that are
+ * illegal in a filesystem path on some platforms, e.g. the {@code ':'} of
a port
+ * ({@code host:8080/repo}), and must normalize identically everywhere.
+ * <ul>
+ * <li>Trailing separators are significant (e.g. {@code
http://host/repo/} is not
+ * {@code http://host/repo}) and are preserved.</li>
+ * <li>Redundant separators, {@code "."} and resolvable {@code ".."}
segments are collapsed.</li>
+ * <li>Excess {@code ".."} segments that would climb above the path root
are preserved
+ * instead of being silently dropped.</li>
Review Comment:
doc comments need to focus on what a method does, not implementation or a
bug that was fixed in the past. e.g. all you need to say is "Normalizes the
path part of an SCM URL".
##########
src/test/java/org/apache/maven/plugin/resources/remote/ModelInheritanceAssemblerTest.java:
##########
@@ -0,0 +1,81 @@
+/*
+ * 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.
+ */
+package org.apache.maven.plugin.resources.remote;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Unit tests for the SCM path normalization in {@link
ModelInheritanceAssembler}.
+ */
+public class ModelInheritanceAssemblerTest {
+
+ private final ModelInheritanceAssembler assembler = new
ModelInheritanceAssembler();
+
+ @Test
+ public void appendPathPreservesTrailingSlash() {
+ assertEquals(
+ "http://svn.example.com/repo/",
+ assembler.appendPath("http://svn.example.com/repo/", null,
null, false));
+ }
+
+ @Test
+ public void appendPathAppendsChild() {
+ assertEquals(
+ "http://svn.example.com/repo/child",
+ assembler.appendPath("http://svn.example.com/repo", "child",
null, true));
+ }
+
+ @Test
+ public void appendPathCollapsesDotSegment() {
+ assertEquals(
+ "http://svn.example.com/repo/child",
+ assembler.appendPath("http://svn.example.com/repo/./child",
null, null, false));
+ }
+
+ @Test
+ public void appendPathResolvesParentDirectory() {
+ assertEquals(
+ "http://svn.example.com/repos",
+
assembler.appendPath("http://svn.example.com/repos/project/..", null, null,
false));
+ }
+
+ @Test
+ public void appendPathCollapsesRedundantSeparators() {
+ assertEquals(
+ "http://svn.example.com/repo/child",
+ assembler.appendPath("http://svn.example.com/repo//child",
null, null, false));
+ }
+
+ @Test
+ public void appendPathPreservesExcessParentDirectory() {
+ assertEquals("../x", assembler.appendPath("a/../../x", null, null,
false));
+ }
+
+ /**
+ * A segment containing {@code ':'} (a port, as common in SVN/git SCM
URLs) is an illegal
Review Comment:
delete "where {@code Paths.get(...)} throws {@link
java.nio.file.InvalidPathException}."
--
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]