Skip to content

Commit

Permalink
[backend] handle case if multiline inside if statement
Browse files Browse the repository at this point in the history
Signed-off-by: Marine LM <[email protected]>
  • Loading branch information
MarineLeM committed Jan 2, 2025
1 parent b9bf3dd commit c769605
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static String replaceCmdVariables(String cmd) {
private static String formatMultilineCommand(String command) {
String[] lines = command.split("\n");
StringBuilder formattedCommand = new StringBuilder();
boolean insideBlock = false;

for (int i = 0; i < lines.length; i++) {
String line = lines[i];
Expand All @@ -86,16 +85,11 @@ private static String formatMultilineCommand(String command) {
}
formattedCommand.append(trimmedLine);

if (trimmedLine.endsWith("(")) {
insideBlock = true;
}

if (trimmedLine.endsWith(")")) {
insideBlock = false;
}

boolean isLastLine = (i == lines.length - 1);
if (!insideBlock && !isLastLine) {
boolean isAfterParentheses = trimmedLine.endsWith("(");
boolean isBeforeParentheses = !isLastLine && lines[i + 1].trim().startsWith(")");

if (!isAfterParentheses && !isBeforeParentheses && !isLastLine) {
formattedCommand.append(" & ");
} else {
formattedCommand.append(" ");
Expand All @@ -116,6 +110,7 @@ private String processAndEncodeCommand(
if (executor.equals("cmd")) {
computedCommand = replaceCmdVariables(computedCommand);
computedCommand = formatMultilineCommand(computedCommand);
System.out.println("computed command : " + computedCommand);
}

if (obfuscator.equals("base64")) {
Expand Down

0 comments on commit c769605

Please sign in to comment.