Skip to content

Commit 4b89979

Browse files
Ikem Nzeribeclaude
andcommitted
Fix script corruption in executeJxa shell-escape
executeJxa built the osascript command as a shell string and escaped single quotes with `'` -> `''`. That is not a valid bash escape inside a single-quoted string; `''` collapses to nothing, so every apostrophe in the JXA script was silently stripped before reaching osascript. The bug is latent today because the project's JXA strings use double quotes throughout, but any tool emitting a single-quoted JXA string literal (an `'foo'`, an apostrophe in a thrown error message, etc.) would produce a syntax error or, worse, a silently malformed script. Switch to execFile with an argv array. osascript receives the script as a single argument, no shell interpretation, no escaping needed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 03fba2d commit 4b89979

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

src/applescript/execute.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { exec } from "child_process";
1+
import { execFile } from "child_process";
22
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
33
export const executeJxa = <T>(script: string): Promise<T> => {
44
return new Promise((resolve, reject) => {
5-
const command = `osascript -l JavaScript -e '${script.replace(/'/g, "''")}'`;
6-
exec(command, (error, stdout, stderr) => {
5+
execFile("osascript", ["-l", "JavaScript", "-e", script], (error, stdout, stderr) => {
76
if (error) {
87
return reject(
98
new McpError(ErrorCode.InternalError, `JXA execution failed: ${error.message}`),

0 commit comments

Comments
 (0)