Skip to content

Commit

Permalink
expand: do not panic on extglob nodes
Browse files Browse the repository at this point in the history
we currently don't support bash's `extglob` option and when attempted,
interp panics

fix expand so that we return the error properly and exit with status `1`

fixes #841
  • Loading branch information
riacataquian authored and mvdan committed Jun 10, 2022
1 parent 7164cd1 commit 11787f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions expand/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ func (cfg *Config) wordFields(wps []syntax.WordPart) ([][]fieldPart, error) {
return nil, err
}
splitAdd(path)
case *syntax.ExtGlob:
return nil, fmt.Errorf("extended globbing is not supported")
default:
panic(fmt.Sprintf("unhandled word part: %T", x))
}
Expand Down
3 changes: 3 additions & 0 deletions interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,9 @@ set +o pipefail
"shopt -s nullglob; touch existing-1; echo missing-* existing-*",
"existing-1\n",
},
// Extended globbing is not supported
{"ls ab+(2|3).txt", "extended globbing is not supported\nexit status 1 #JUSTERR"},
{"echo *(/)", "extended globbing is not supported\nexit status 1 #JUSTERR"},
// Ensure that setting nullglob does not return invalid globs as null
// strings.
{
Expand Down

0 comments on commit 11787f5

Please sign in to comment.