Skip to content

Commit 543a73f

Browse files
authored
[run] escape quotes in arguments (#1144)
## Summary Implementing a narrow fix for #1137 We wrap each command arg in double-quotes and escape any double-quotes within. Fixes #1137 ## How was it tested? Added testscript unit test from issue: ``` > devbox run -- jq -r '.shell.scripts | keys | join(" ")' devbox.json build build-linux build-linux-amd64 code lint test ``` Also, this now matches: ``` > echo 'hello "world"' hello "world" > devbox run -- echo 'hello "world"' hello "world" ``` previously: ``` > devbox run -- echo 'hello "world"' hello world ```
1 parent 0102dad commit 543a73f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/impl/devbox.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
263263
return err
264264
}
265265

266+
// wrap the arg in double-quotes, and escape any double-quotes inside it
267+
for idx, arg := range cmdArgs {
268+
cmdArgs[idx] = strconv.Quote(arg)
269+
}
270+
266271
var cmdWithArgs []string
267272
if _, ok := d.cfg.Scripts()[cmdName]; ok {
268273
// it's a script, so replace the command with the script file's path.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ensure that we escape the arguments to `devbox run`
2+
3+
exec devbox init
4+
exec devbox run -- echo 'this is a "hello world"'
5+
stdout 'this is a "hello world"'
6+
7+
env FOO=bar
8+
exec devbox run echo '$FOO'
9+
stdout 'bar'
10+
11+
exec devbox run echo "$FOO"
12+
stdout 'bar'

0 commit comments

Comments
 (0)