Skip to content

Commit ca34757

Browse files
committed
fix: preserve trailing slashes in Windows JDK 8 arguments
1 parent 740608c commit ca34757

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎.github/workflows/platform-contracts.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ jobs:
5757
--suite argv=io.github.easy4j.opencli.contract.OpenCliArgvContractTest \
5858
--suite argv=io.github.easy4j.opencli.contract.OpenCliStructuredArgvContractTest \
5959
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessContractTest \
60-
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessBoundaryTest,SubprocessStreamFailureTest \
61-
--suite cleanup=io.github.easy4j.opencli.core.support.SubprocessStreamFailureTest \
60+
--suite process=io.github.easy4j.opencli.contract.OpenCliProcessBoundaryTest \
61+
--suite process=io.github.easy4j.opencli.core.support.SubprocessStreamFailureTest \
6262
--output platform-evidence/report.json
6363
exit "$result"
6464
- name: Upload platform subprocess evidence

‎src/main/java/io/github/easy4j/opencli/core/support/SubprocessExecutionSupport.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,17 @@ private static String quoteWindowsExecutableArgument(String argument) {
347347
quoted.append(character);
348348
backslashes = 0;
349349
}
350+
quoted.append('"');
351+
if (backslashes == 0) {
352+
return quoted.toString();
353+
}
354+
355+
// JDK 8 treats a final quote after a backslash as escaped. Close the quoted
356+
// text first and use an empty quoted segment after the escaped trailing slashes.
350357
for (int i = 0; i < backslashes * 2; i++) {
351358
quoted.append('\\');
352359
}
353-
return quoted.append('"').toString();
360+
return quoted.append('"').append('"').toString();
354361
}
355362

356363
private static long elapsedMillis(long start) { return TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start); }

0 commit comments

Comments
 (0)