Copilot commented on code in PR #1349:
URL: https://github.com/apache/maven-scm/pull/1349#discussion_r2646845293


##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java:
##########
@@ -104,7 +104,7 @@ public static String maskPasswordInUrl(String 
urlWithCredentials) {
             // clear password with delimiters
             final String clearPasswordWithDelimiters = 
passwordMatcher.group(1);
             // to be replaced in output by stars with delimiters
-            output = StringUtils.replace(output, clearPasswordWithDelimiters, 
PASSWORD_PLACE_HOLDER_WITH_DELIMITERS);
+            output = Strings.CS.replace(output, clearPasswordWithDelimiters, 
PASSWORD_PLACE_HOLDER_WITH_DELIMITERS);

Review Comment:
   The API `Strings.CS.replace()` does not exist in Apache Commons Lang3. The 
correct API is `StringUtils.replace()`. The import should be 
`org.apache.commons.lang3.StringUtils` and the method call should be 
`StringUtils.replace(output, clearPasswordWithDelimiters, 
PASSWORD_PLACE_HOLDER_WITH_DELIMITERS)`.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/test/java/org/apache/maven/scm/provider/git/util/GitUtilTest.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * 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.scm.provider.git.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test for {@link GitUtil}
+ */
+public class GitUtilTest {
+
+    @Test
+    public void testMaskPasswordInUrlWithPort() {
+        // URL with port
+        String urlWithPort = "https://user:password@host:8080/repo.git";;
+        String maskedWithPort = GitUtil.maskPasswordInUrl(urlWithPort);
+        assertEquals("Password should be masked in URL with port",
+                "https://user:********@host:8080/repo.git";, maskedWithPort);
+    }
+
+    @Test
+    public void testMaskPasswordInUrlWithoutPort() {
+        // URL without port
+        String url = "https://user:password@host/repo.git";;
+        String masked = GitUtil.maskPasswordInUrl(url);
+        assertEquals("Password should be masked in URL without port",
+                "https://user:********@host/repo.git";, masked);
+    }
+
+    @Test
+    public void testMaskPasswordInUrlNoPassword() {
+        // URL with no password
+        String noPassword = "https://user@host/repo.git";;
+        assertEquals("URL without password should remain unchanged",
+                noPassword, GitUtil.maskPasswordInUrl(noPassword));
+    }
+
+    @Test
+    public void testMaskPasswordInUrlNoUser() {
+        // URL with no user
+        String noUser = "https://host/repo.git";;
+        assertEquals("URL without user should remain unchanged",
+                noUser, GitUtil.maskPasswordInUrl(noUser));
+    }

Review Comment:
   Consider adding a test case for URLs with empty passwords (e.g., 
`https://user:@host/repo.git`). While the current regex pattern `:[^@/]+@` 
won't match this case (which may be intentional), it would be good to document 
this behavior with an explicit test to clarify that URLs with empty passwords 
are not modified.



##########
maven-scm-providers/maven-scm-providers-git/maven-scm-provider-git-commons/src/main/java/org/apache/maven/scm/provider/git/util/GitUtil.java:
##########
@@ -23,7 +23,7 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.Strings;

Review Comment:
   The import statement is incorrect. It should be `import 
org.apache.commons.lang3.StringUtils;` instead of `import 
org.apache.commons.lang3.Strings;`. The class `Strings` with a `CS` field does 
not exist in Apache Commons Lang3.



-- 
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]

Reply via email to