Skip to content

Commit 52cdb7a

Browse files
authored
Disallow script names with whitespace in them (#500)
## Summary We shouldn't have allowed this in the first place, but if we allow it, then it's impossible to support arbitrary commands, as well as passing args to a script. Improves error messages a bit by including the script name. ## How was it tested? Added spaces to some scripts in `devbox.json` and called `devbox run` ### NOTE: this is a breaking change for any devbox.json with scripts that have whitespace. Since the fix is trivial, I thought it's reasonable to release it without backwards-compatibility.
1 parent 3cadef8 commit 52cdb7a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/impl/config.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package impl
66
import (
77
"os"
88
"path/filepath"
9+
"regexp"
910
"strings"
1011

1112
"github.com/pkg/errors"
@@ -186,13 +187,19 @@ func validateConfig(cfg *Config) error {
186187
}
187188
return nil
188189
}
190+
191+
var whitespace = regexp.MustCompile(`\s`)
192+
189193
func validateScripts(cfg *Config) error {
190194
for k := range cfg.Shell.Scripts {
191195
if strings.TrimSpace(k) == "" {
192196
return errors.New("cannot have script with empty name in devbox.json")
193197
}
198+
if whitespace.MatchString(k) {
199+
return errors.Errorf("cannot have script name with whitespace in devbox.json: %s", k)
200+
}
194201
if strings.TrimSpace(cfg.Shell.Scripts[k].String()) == "" {
195-
return errors.New("cannot have an empty script value in devbox.json")
202+
return errors.Errorf("cannot have an empty script body in devbox.json: %s", k)
196203
}
197204
}
198205
return nil

0 commit comments

Comments
 (0)