Skip to content

Commit

Permalink
fix: escape string arguments when calling OpenSCAD
Browse files Browse the repository at this point in the history
  • Loading branch information
seasick committed Jan 21, 2024
1 parent c9f47f3 commit b910f88
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/openSCADWorker.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ async function exportFile(
fileType = 'stl'
): Promise<OpenSCADWorkerOutputMessage> {
const parameters = params.map(({ name, value }) => {
if (typeof value === 'string') {
value = escapeShell(value);
}
return `-D${name}=${value}`;
});

Expand All @@ -51,6 +54,9 @@ async function preview(
fileType = 'stl'
): Promise<OpenSCADWorkerOutputMessage> {
const parameters = params.map(({ name, value }) => {
if (typeof value === 'string') {
value = escapeShell(value);
}
return `-D${name}=${value}`;
});

Expand Down Expand Up @@ -119,3 +125,7 @@ async function executeOpenscad(

return { output, exitCode, duration: Date.now() - start, log };
}

function escapeShell(cmd: string) {
return '"' + cmd.replace(/(["'$`\\])/g, '\\$1') + '"';
}

0 comments on commit b910f88

Please sign in to comment.