Skip to content

Commit

Permalink
[run] escape quotes in arguments (jetify-com#1144)
Browse files Browse the repository at this point in the history
## Summary

Implementing a narrow fix for jetify-com#1137
We wrap each command arg in double-quotes and escape any double-quotes
within.

Fixes jetify-com#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
```
  • Loading branch information
savil authored Jun 13, 2023
1 parent 0102dad commit 543a73f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions internal/impl/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ func (d *Devbox) RunScript(ctx context.Context, cmdName string, cmdArgs []string
return err
}

// wrap the arg in double-quotes, and escape any double-quotes inside it
for idx, arg := range cmdArgs {
cmdArgs[idx] = strconv.Quote(arg)
}

var cmdWithArgs []string
if _, ok := d.cfg.Scripts()[cmdName]; ok {
// it's a script, so replace the command with the script file's path.
Expand Down
12 changes: 12 additions & 0 deletions testscripts/run/quote_escaping.test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# ensure that we escape the arguments to `devbox run`

exec devbox init
exec devbox run -- echo 'this is a "hello world"'
stdout 'this is a "hello world"'

env FOO=bar
exec devbox run echo '$FOO'
stdout 'bar'

exec devbox run echo "$FOO"
stdout 'bar'

0 comments on commit 543a73f

Please sign in to comment.