execution: Escape newline chars on Windows

This commit is contained in:
Eldar Abusalimov
2017-08-31 16:40:28 +03:00
parent d2429f0708
commit c1743148bb
2 changed files with 5 additions and 7 deletions
@@ -66,6 +66,8 @@ public class GeneralCommandLineTest {
"\"quoted-slash\\\"",
"\"quoted-two-slashes\\\\\"",
"some\ttab",
"new\nline",
"\nnew\nline\n",
"^% % %%% %\"%%",
//"%PATH%",
"^",
@@ -34,7 +34,7 @@ public class CommandLineUtil {
private static final Pattern WIN_BACKSLASHES_PRECEDING_QUOTE = Pattern.compile("(\\\\+)(?=\"|$)");
private static final Pattern WIN_CARET_SPECIAL = Pattern.compile("[&<>()@^|!%]");
private static final Pattern WIN_QUOTE_SPECIAL = Pattern.compile("[ \t\"*?\\[{}~()\']"); // + glob [*?] + Cygwin glob [*?\[{}~] + [()']
private static final Pattern WIN_QUOTE_SPECIAL = Pattern.compile("[ \t\\r\\n\"*?\\[{}~()\']"); // + glob [*?] + Cygwin glob [*?\[{}~] + [()']
private static final Pattern WIN_QUIET_COMMAND = Pattern.compile("((?:@\\s*)++)(.*)", Pattern.CASE_INSENSITIVE);
private static final char Q = '\"';
@@ -464,12 +464,8 @@ public class CommandLineUtil {
@NotNull
@Contract(pure = true)
public static String escapeParameterOnWindows(@NotNull String parameter, boolean isWinShell) {
String s = convertLineSeparators(parameter, "");
if (s.isEmpty()) return QQ;
boolean hadLineBreaks = !s.equals(parameter);
String result = isWinShell ? escapeParameter(s, new QuoteFlag(hadLineBreaks), 1, true) : backslashEscapeQuotes(s);
if (hadLineBreaks) result = quote(result, Q);
return result;
if (parameter.isEmpty()) return QQ;
return isWinShell ? escapeParameter(parameter, new QuoteFlag(false), 1, true) : backslashEscapeQuotes(parameter);
}
@NotNull