Skip to content

Commit

Permalink
interp: don't crash on declaring empty names
Browse files Browse the repository at this point in the history
Updates mvdan#332.
  • Loading branch information
mvdan committed Dec 6, 2018
1 parent 2df1ac9 commit ca54214
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ func (r *Runner) cmd(ctx context.Context, cm syntax.Command) {
for _, as := range x.Assigns {
for _, as := range r.flattenAssign(as) {
name := as.Name.Value
if !syntax.ValidName(name) {
r.errf("declare: invalid name %q\n", name)
r.exit = 1
return
}
vr := r.lookupVar(as.Name.Value)
vr.Value = r.assignVal(as, valType)
if global {
Expand Down
2 changes: 2 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ set +o pipefail
{"a=x=y; declare $a; echo $a $x", "x=y y\n"},
{"a='x=(y)'; declare $a; echo $a $x", "x=(y) (y)\n"},
{"a='x=b y=c'; declare $a; echo $x $y", "b c\n"},
{"declare =bar", "declare: invalid name \"=bar\"\nexit status 1 #JUSTERR"},
{"declare $unset=$unset", "declare: invalid name \"\"\nexit status 1 #JUSTERR"},

// export
{"declare foo=bar; env | grep '^foo='", "exit status 1"},
Expand Down

0 comments on commit ca54214

Please sign in to comment.