elharo commented on code in PR #112: URL: https://github.com/apache/maven-jarsigner/pull/112#discussion_r3838531336
########## src/test/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilderTest.java: ########## @@ -0,0 +1,115 @@ +/* + * 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.shared.jarsigner; + +import java.io.File; +import java.util.Arrays; + +import org.apache.maven.shared.utils.cli.Commandline; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class JarSignerCommandLineBuilderTest { + + private JarSignerCommandLineBuilder builder; + private JarSignerSignRequest request; + + private static final boolean IS_WINDOWS = Review Comment: toLowerCase needs a Locale. ########## src/main/java/org/apache/maven/shared/jarsigner/JarSignerCommandLineBuilder.java: ########## @@ -138,13 +138,44 @@ protected void checkRequiredState() throws CommandLineConfigurationException { } } + /** + * Escapes special cmd.exe characters in a password string with {@code ^}. + * On Windows, passwords are passed on the command line and characters like {@code &} + * are interpreted by cmd.exe as command separators unless escaped. + * On other platforms this is a no-op since the shell handles quoting correctly. + * + * @param password the password to escape + * @return the escaped password, or {@code null} if the input is {@code null} + */ + static String escapePassword(String password) { + if (password == null || password.isEmpty()) { + return password; + } + if (!isWindows()) { Review Comment: This check should be before this method is called, not inside this method. -- 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]
