mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
Improve now() and date() validation
This commit is contained in:
+2
-2
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user