Skip to content

Commit 8616d77

Browse files
committed
Replace JSON.stringify with shescape.quote for proper shell escaping
1 parent 8be45ef commit 8616d77

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/runtime/SSHRuntime.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export class SSHRuntime implements Runtime {
377377
let originUrl: string | null = null;
378378
try {
379379
using proc = execAsync(
380-
`cd ${JSON.stringify(projectPath)} && git remote get-url origin 2>/dev/null || true`
380+
`cd ${shescape.quote(projectPath)} && git remote get-url origin 2>/dev/null || true`
381381
);
382382
const { stdout } = await proc.result;
383383
const url = stdout.trim();
@@ -394,7 +394,7 @@ export class SSHRuntime implements Runtime {
394394
initLogger.logStep(`Creating git bundle...`);
395395
await new Promise<void>((resolve, reject) => {
396396
const sshArgs = this.buildSSHArgs(true);
397-
const command = `cd ${JSON.stringify(projectPath)} && git bundle create - --all | ssh ${sshArgs.join(" ")} "cat > ${bundleTempPath}"`;
397+
const command = `cd ${shescape.quote(projectPath)} && git bundle create - --all | ssh ${sshArgs.join(" ")} "cat > ${bundleTempPath}"`;
398398

399399
log.debug(`Creating bundle: ${command}`);
400400
const bashPath = findBashPath();
@@ -449,7 +449,7 @@ export class SSHRuntime implements Runtime {
449449
if (originUrl) {
450450
initLogger.logStep(`Setting origin remote to ${originUrl}...`);
451451
const setOriginStream = await this.exec(
452-
`git -C ${cloneDestPath} remote set-url origin ${JSON.stringify(originUrl)}`,
452+
`git -C ${cloneDestPath} remote set-url origin ${shescape.quote(originUrl)}`,
453453
{
454454
cwd: "~",
455455
timeout: 10,
@@ -663,7 +663,7 @@ export class SSHRuntime implements Runtime {
663663
// We create new branches from HEAD instead of the trunkBranch name to avoid issues
664664
// where the local repo's trunk name doesn't match the cloned repo's default branch
665665
initLogger.logStep(`Checking out branch: ${branchName}`);
666-
const checkoutCmd = `(git checkout ${JSON.stringify(branchName)} 2>/dev/null || git checkout -b ${JSON.stringify(branchName)} HEAD)`;
666+
const checkoutCmd = `(git checkout ${shescape.quote(branchName)} 2>/dev/null || git checkout -b ${shescape.quote(branchName)} HEAD)`;
667667

668668
const checkoutStream = await this.exec(checkoutCmd, {
669669
cwd: workspacePath, // Use the full workspace path for git operations

0 commit comments

Comments
 (0)