setup-sdl: Escape all arguments when concatenating

From c3f966b577bda4aa30a21fab1875fc89f0151a6b Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Sun, 26 May 2024 00:55:44 +0200
Subject: [PATCH] Escape all arguments when concatenating

---
 packed/index.js | 12 ++++++++----
 src/main.ts     |  8 ++++----
 src/util.ts     |  4 ++++
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/packed/index.js b/packed/index.js
index 76987fa..7b11f29 100644
--- a/packed/index.js
+++ b/packed/index.js
@@ -268,7 +268,7 @@ function cmake_configure_build(args) {
                             var configure_command;
                             return __generator(this, function (_a) {
                                 core.debug("configure_args: ".concat(configure_args));
-                                configure_command = configure_args.join(" ");
+                                configure_command = (0, util_1.command_arglist_to_string)(configure_args);
                                 core.debug("configure_command: ".concat(configure_command));
                                 args.executor.run(configure_command, true);
                                 return [2 /*return*/];
@@ -280,7 +280,7 @@ function cmake_configure_build(args) {
                             var build_command;
                             return __generator(this, function (_a) {
                                 core.debug("build_args: ".concat(build_args));
-                                build_command = build_args.join(" ");
+                                build_command = (0, util_1.command_arglist_to_string)(build_args);
                                 core.debug("build_command: ".concat(build_command));
                                 args.executor.run(build_command, true);
                                 return [2 /*return*/];
@@ -292,7 +292,7 @@ function cmake_configure_build(args) {
                             var install_command;
                             return __generator(this, function (_a) {
                                 core.debug("install_args: ".concat(install_args));
-                                install_command = install_args.join(" ");
+                                install_command = (0, util_1.command_arglist_to_string)(install_args);
                                 core.debug("install_command: ".concat(install_command));
                                 args.executor.run(install_command, true);
                                 return [2 /*return*/];
@@ -1298,7 +1298,7 @@ var __extends = (this && this.__extends) || (function () {
     };
 })();
 Object.defineProperty(exports, "__esModule", ({ value: true }));
-exports.shlex_split = exports.SetupSdlError = void 0;
+exports.command_arglist_to_string = exports.shlex_split = exports.SetupSdlError = void 0;
 var shlex = __nccwpck_require__(5659);
 var SetupSdlError = /** @class */ (function (_super) {
     __extends(SetupSdlError, _super);
@@ -1321,6 +1321,10 @@ function shlex_split(text) {
     }
 }
 exports.shlex_split = shlex_split;
+function command_arglist_to_string(args) {
+    return args.map(function (s) { return "\"".concat(s, "\""); }).join(" ");
+}
+exports.command_arglist_to_string = command_arglist_to_string;
 
 
 /***/ }),
diff --git a/src/main.ts b/src/main.ts
index c821bec..2d88c10 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -10,7 +10,7 @@ import { Octokit } from "@octokit/rest";
 import AdmZip = require("adm-zip");
 
 import { convert_git_branch_tag_to_hash } from "./repo";
-import { SetupSdlError, shlex_split } from "./util";
+import { SetupSdlError, command_arglist_to_string, shlex_split } from "./util";
 import * as pm from "./pm";
 
 import { GitHubRelease, ReleaseDb, ReleaseType } from "./version";
@@ -207,19 +207,19 @@ async function cmake_configure_build(args: {
 
   await core.group(`Configuring ${args.project} (CMake)`, async () => {
     core.debug(`configure_args: ${configure_args}`);
-    const configure_command = configure_args.join(" ");
+    const configure_command = command_arglist_to_string(configure_args);
     core.debug(`configure_command: ${configure_command}`);
     args.executor.run(configure_command, true);
   });
   await core.group(`Building ${args.project} (CMake)`, async () => {
     core.debug(`build_args: ${build_args}`);
-    const build_command = build_args.join(" ");
+    const build_command = command_arglist_to_string(build_args);
     core.debug(`build_command: ${build_command}`);
     args.executor.run(build_command, true);
   });
   await core.group(`Installing ${args.project} (CMake)`, async () => {
     core.debug(`install_args: ${install_args}`);
-    const install_command = install_args.join(" ");
+    const install_command = command_arglist_to_string(install_args);
     core.debug(`install_command: ${install_command}`);
     args.executor.run(install_command, true);
   });
diff --git a/src/util.ts b/src/util.ts
index caf7d50..5684245 100644
--- a/src/util.ts
+++ b/src/util.ts
@@ -17,3 +17,7 @@ export function shlex_split(text: undefined | string): string[] {
     return shlex.split(text);
   }
 }
+
+export function command_arglist_to_string(args: string[]): string {
+  return args.map((s) => `"${s}"`).join(" ");
+}