diff --git a/src/openSCADWorker.mts b/src/openSCADWorker.mts index 03a6124..12d93b3 100644 --- a/src/openSCADWorker.mts +++ b/src/openSCADWorker.mts @@ -32,6 +32,9 @@ async function exportFile( fileType = 'stl' ): Promise { const parameters = params.map(({ name, value }) => { + if (typeof value === 'string') { + value = escapeShell(value); + } return `-D${name}=${value}`; }); @@ -51,6 +54,9 @@ async function preview( fileType = 'stl' ): Promise { const parameters = params.map(({ name, value }) => { + if (typeof value === 'string') { + value = escapeShell(value); + } return `-D${name}=${value}`; }); @@ -119,3 +125,7 @@ async function executeOpenscad( return { output, exitCode, duration: Date.now() - start, log }; } + +function escapeShell(cmd: string) { + return '"' + cmd.replace(/(["'$`\\])/g, '\\$1') + '"'; +}