Skip to content

Commit

Permalink
topdown: Correct glob default delimeter
Browse files Browse the repository at this point in the history
The documentation says that the default delimeter for glob is `["."]`
but the implementation did not actually do this (for the normal built
in).

This corrects the implementation to actually default to the correct
value when it is omitted.

Fixes: #2039
Signed-off-by: Patrick East <[email protected]>
  • Loading branch information
patrick-east authored and tsandall committed Feb 6, 2020
1 parent 60cf8aa commit 0fe6394
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions topdown/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func builtinGlobMatch(a, b, c ast.Value) (ast.Value, error) {
return nil, err
}

if len(delimiters) == 0 {
delimiters = []rune{'.'}
}

match, err := builtins.StringOperand(c, 3)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions topdown/glob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ func TestGlobMatch(t *testing.T) {
{"glob match with pattern-alternatives list (fat)", []string{`p[x] { glob.match("{cat,bat,[fr]at}", [], "fat", x) }`}, "[true]"},
{"glob match with pattern-alternatives list (rat)", []string{`p[x] { glob.match("{cat,bat,[fr]at}", [], "rat", x) }`}, "[true]"},
{"glob no match with pattern-alternatives list", []string{`p[x] { glob.match("{cat,bat,[fr]at}", [], "at", x) }`}, "[false]"},
{"glob match single with . delimiter", []string{`p[x] { glob.match("*", ["."], "foo", x) }`}, "[true]"},
{"glob match single with default delimiter", []string{`p[x] { glob.match("*", [], "foo", x) }`}, "[true]"},
{"glob no match single with . delimiter", []string{`p[x] { glob.match("*", ["."], "foo.bar", x) }`}, "[false]"},
{"glob no match single with default delimiter", []string{`p[x] { glob.match("*", [], "foo.bar", x) }`}, "[false]"},
}

data := loadSmallTestData()
Expand Down

0 comments on commit 0fe6394

Please sign in to comment.