Skip to content

Commit

Permalink
Improve now() and date() validation
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed May 8, 2024
1 parent 6171d56 commit 1a5df77
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ var Builtins = []*Function{
return timeType, nil
}
if len(args) == 1 {
if args[0].AssignableTo(locationType) {
if args[0] != nil && args[0].AssignableTo(locationType) {
return timeType, nil
}
}
Expand Down Expand Up @@ -559,7 +559,7 @@ var Builtins = []*Function{
if len(args) < 1 {
return anyType, fmt.Errorf("invalid number of arguments (expected at least 1, got %d)", len(args))
}
if args[0].AssignableTo(locationType) {
if args[0] != nil && args[0].AssignableTo(locationType) {
args = args[1:]
}
if len(args) > 3 {
Expand Down
3 changes: 3 additions & 0 deletions builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ func TestBuiltin_errors(t *testing.T) {
{`bitshr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"},
{`bitshl(1, -1)`, "invalid operation: negative shift count -1 (type int) (1:1)"},
{`bitushr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"},
{`now(nil)`, "invalid number of arguments (expected 0, got 1)"},
{`date(nil)`, "interface {} is nil, not string (1:1)"},
{`timezone(nil)`, "interface {} is nil, not string (1:1)"},
}
for _, test := range errorTests {
t.Run(test.input, func(t *testing.T) {
Expand Down

0 comments on commit 1a5df77

Please sign in to comment.