mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-01-24 14:34:15 +08:00
fix(launch): not escape spaces in exported shell script. Closes #1541.
This commit is contained in:
parent
a80fc34ef1
commit
3c3c28aaa5
@ -601,7 +601,7 @@ public class DefaultLauncher extends Launcher {
|
||||
writer.write("set APPDATA=" + options.getGameDir().getAbsoluteFile().getParent());
|
||||
writer.newLine();
|
||||
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();
|
||||
@ -610,7 +610,7 @@ public class DefaultLauncher extends Launcher {
|
||||
writer.write("#!/usr/bin/env bash");
|
||||
writer.newLine();
|
||||
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();
|
||||
}
|
||||
if (commandLine.tempNativeFolder != null) {
|
||||
|
@ -47,9 +47,9 @@ public final class CommandBuilder {
|
||||
|
||||
private String parse(String s) {
|
||||
if (OperatingSystem.WINDOWS == os) {
|
||||
return parseBatch(s);
|
||||
return toBatchStringLiteral(s);
|
||||
} else {
|
||||
return parseShell(s);
|
||||
return toShellStringLiteral(s);
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ public final class CommandBuilder {
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
private static String parseBatch(String s) {
|
||||
public static String toBatchStringLiteral(String s) {
|
||||
String escape = " \t\"^&<>|";
|
||||
if (StringUtils.containsOne(s, escape.toCharArray()))
|
||||
// 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 escaped = "\"$&`";
|
||||
if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0 || StringUtils.containsOne(s, escaping.toCharArray())) {
|
||||
|
Loading…
Reference in New Issue
Block a user