From 2efefc01ca61f4eccf2bf5021518762bedb35b76 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Tue, 10 Oct 2023 15:00:25 +0200 Subject: [PATCH] Revert to previous version of `escapeArg()`. (#515) This should fix Windows path escaping issues. Closes #511. --- .../buildtools/utils/NativeImageUtils.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java b/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java index c20023f10..e3f0d9f36 100644 --- a/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java +++ b/common/utils/src/main/java/org/graalvm/buildtools/utils/NativeImageUtils.java @@ -105,21 +105,14 @@ public static List convertToArgsFile(List cliArgs, Path outputDi } - /** - * See https://github.com/oracle/graal/blob/f011d4d056a7ed78fe9669cc38062e6d09c14bed/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java#L1447C47-L1447C60. - */ public static String escapeArg(String arg) { - if (arg.isEmpty()) { - return "''"; - } - Matcher m = SAFE_SHELL_ARG.matcher(arg); - if (m.matches()) { - return arg; + if (!(arg.startsWith("\\Q") && arg.endsWith("\\E"))) { + arg = arg.replace("\\", "\\\\"); + if (arg.contains(" ")) { + arg = "\"" + arg + "\""; + } } - return "'" + arg - .replace("'", "'\"'\"'") - .replace("\\", "\\\\") /* for Windows paths */ - + "'"; + return arg; }