fix(launch): not escape spaces in exported shell script. Closes #1541.
This commit is contained in:
@@ -601,7 +601,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
||||||
writer.write("set " + entry.getKey() + "=" + entry.getValue());
|
writer.write("set " + entry.getKey() + "=" + CommandBuilder.toBatchStringLiteral(entry.getValue()));
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
@@ -610,7 +610,7 @@ public class DefaultLauncher extends Launcher {
|
|||||||
writer.write("#!/usr/bin/env bash");
|
writer.write("#!/usr/bin/env bash");
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
for (Map.Entry<String, String> entry : getEnvVars().entrySet()) {
|
||||||
writer.write("export " + entry.getKey() + "=" + entry.getValue());
|
writer.write("export " + entry.getKey() + "=" + CommandBuilder.toShellStringLiteral(entry.getValue()));
|
||||||
writer.newLine();
|
writer.newLine();
|
||||||
}
|
}
|
||||||
if (commandLine.tempNativeFolder != null) {
|
if (commandLine.tempNativeFolder != null) {
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ public final class CommandBuilder {
|
|||||||
|
|
||||||
private String parse(String s) {
|
private String parse(String s) {
|
||||||
if (OperatingSystem.WINDOWS == os) {
|
if (OperatingSystem.WINDOWS == os) {
|
||||||
return parseBatch(s);
|
return toBatchStringLiteral(s);
|
||||||
} else {
|
} else {
|
||||||
return parseShell(s);
|
return toShellStringLiteral(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,7 +164,7 @@ public final class CommandBuilder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return parse ? (OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OS ? parseBatch(arg) : parseShell(arg)) : arg;
|
return parse ? (OperatingSystem.WINDOWS == OperatingSystem.CURRENT_OS ? toBatchStringLiteral(arg) : toShellStringLiteral(arg)) : arg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ public final class CommandBuilder {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parseBatch(String s) {
|
public static String toBatchStringLiteral(String s) {
|
||||||
String escape = " \t\"^&<>|";
|
String escape = " \t\"^&<>|";
|
||||||
if (StringUtils.containsOne(s, escape.toCharArray()))
|
if (StringUtils.containsOne(s, escape.toCharArray()))
|
||||||
// The argument has not been quoted, add quotes.
|
// The argument has not been quoted, add quotes.
|
||||||
@@ -219,7 +219,7 @@ public final class CommandBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String parseShell(String s) {
|
public static String toShellStringLiteral(String s) {
|
||||||
String escaping = " \t\"!#$&'()*,;<=>?[\\]^`{|}~";
|
String escaping = " \t\"!#$&'()*,;<=>?[\\]^`{|}~";
|
||||||
String escaped = "\"$&`";
|
String escaped = "\"$&`";
|
||||||
if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0 || StringUtils.containsOne(s, escaping.toCharArray())) {
|
if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0 || StringUtils.containsOne(s, escaping.toCharArray())) {
|
||||||
|
|||||||
Reference in New Issue
Block a user