GP-5015: post-review

GP-5015: fix for spaces issue
This commit is contained in:
d-millar 2024-10-22 13:41:39 -04:00
parent a9d2515610
commit 100958880b
2 changed files with 19 additions and 25 deletions

View File

@ -127,33 +127,27 @@ public class ShellUtils {
if (args.isEmpty()) {
return "";
}
StringBuilder line = new StringBuilder(args.get(0));
StringBuilder line = new StringBuilder(genreateArgument(args.get(0)));
for (int i = 1; i < args.size(); i++) {
String a = args.get(i);
if (a.contains(" ")) {
if (a.contains("\"")) {
if (a.contains("'")) {
line.append(" \"");
line.append(a.replace("\"", "\\\""));
line.append("\"");
continue;
}
line.append(" '");
line.append(a);
line.append("'");
continue;
}
line.append(" \"");
line.append(a);
line.append("\"");
continue;
}
line.append(" ");
line.append(a);
line.append(" " + genreateArgument(a));
}
return line.toString();
}
public static String genreateArgument(String a) {
if (a.contains(" ")) {
if (a.contains("\"")) {
if (a.contains("'")) {
return "\"" + a.replace("\"", "\\\"") + "\"";
}
return "'" + a + "'";
}
return "\"" + a + "\"";
}
return a;
}
public static String generateEnvBlock(Map<String, String> env) {
return env.entrySet()
.stream()