Skip to content

Commit 1a5df77

Browse files
committed
Improve now() and date() validation
1 parent 6171d56 commit 1a5df77

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

builtin/builtin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ var Builtins = []*Function{
487487
return timeType, nil
488488
}
489489
if len(args) == 1 {
490-
if args[0].AssignableTo(locationType) {
490+
if args[0] != nil && args[0].AssignableTo(locationType) {
491491
return timeType, nil
492492
}
493493
}
@@ -559,7 +559,7 @@ var Builtins = []*Function{
559559
if len(args) < 1 {
560560
return anyType, fmt.Errorf("invalid number of arguments (expected at least 1, got %d)", len(args))
561561
}
562-
if args[0].AssignableTo(locationType) {
562+
if args[0] != nil && args[0].AssignableTo(locationType) {
563563
args = args[1:]
564564
}
565565
if len(args) > 3 {

builtin/builtin_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,9 @@ func TestBuiltin_errors(t *testing.T) {
233233
{`bitshr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"},
234234
{`bitshl(1, -1)`, "invalid operation: negative shift count -1 (type int) (1:1)"},
235235
{`bitushr(-5, -2)`, "invalid operation: negative shift count -2 (type int) (1:1)"},
236+
{`now(nil)`, "invalid number of arguments (expected 0, got 1)"},
237+
{`date(nil)`, "interface {} is nil, not string (1:1)"},
238+
{`timezone(nil)`, "interface {} is nil, not string (1:1)"},
236239
}
237240
for _, test := range errorTests {
238241
t.Run(test.input, func(t *testing.T) {

0 commit comments

Comments
 (0)