This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit c0d85abd7496ea2f0be9a6bf3915b11196596793 Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Sun Nov 8 17:26:05 2026 +0000 Quote Windows items in the logged command line only when cmd.exe would Matches the old CmdShell output: an item is quoted when it contains whitespace or one of &<>()@^|, so the argLine test sees 'abc def' and the modular test still finds the quoted @argfile. --- .../surefire/extensions/util/Commandline.java | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/Commandline.java b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/Commandline.java index e013bf9ca..33d301a0c 100644 --- a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/Commandline.java +++ b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/Commandline.java @@ -35,6 +35,8 @@ public class Commandline { private static final boolean WINDOWS = System.getProperty("os.name", "").toLowerCase(java.util.Locale.ROOT).startsWith("windows"); + private static final char[] CMD_SPECIAL_CHARS = {' ', '\t', '&', '<', '>', '(', ')', '@', '^', '|'}; + private String executable; private final List<String> arguments = new ArrayList<>(); private final Map<String, String> addedEnvironment = new LinkedHashMap<>(); @@ -146,7 +148,8 @@ public Process execute() throws IOException { } /** - * The command line as text, each item quoted: single quotes on Unix, double quotes on Windows. + * The command line as text, for logging: on Unix every item in single quotes, on Windows an item in double quotes + * only when cmd.exe would need them (whitespace or one of {@code &<>()@^|}), as the shell wrappers used to print it. */ @Override public String toString() { @@ -155,19 +158,26 @@ public String toString() { if (sb.length() > 0) { sb.append(' '); } - if (WINDOWS) { - sb.append('"') - .append(item == null ? "" : item.replace("\"", "\\\"")) - .append('"'); - } else { - sb.append('\'') - .append(item == null ? "" : item.replace("'", "'\"'\"'")) - .append('\''); - } + sb.append(quoteForLog(item == null ? "" : item)); } return sb.toString(); } + private static String quoteForLog(String item) { + if (!WINDOWS) { + return "'" + item.replace("'", "'\"'\"'") + "'"; + } + if (item.isEmpty() || (item.length() > 1 && item.startsWith("\"") && item.endsWith("\""))) { + return item; + } + for (char c : CMD_SPECIAL_CHARS) { + if (item.indexOf(c) >= 0) { + return "\"" + item + "\""; + } + } + return item; + } + /** * Splits a command line into arguments like a shell would: whitespace separates, single or double quotes * group, a backslash escapes the next character.
