@@ -222,6 +222,9 @@ var Builtins = []*Function{
222222 {
223223 Name : "trimPrefix" ,
224224 Func : func (args ... any ) (any , error ) {
225+ if len (args ) == 0 {
226+ return nil , fmt .Errorf ("not enough arguments to call trimPrefix" )
227+ }
225228 s := " "
226229 if len (args ) == 2 {
227230 s = args [1 ].(string )
@@ -236,6 +239,9 @@ var Builtins = []*Function{
236239 {
237240 Name : "trimSuffix" ,
238241 Func : func (args ... any ) (any , error ) {
242+ if len (args ) == 0 {
243+ return nil , fmt .Errorf ("not enough arguments to call trimSuffix" )
244+ }
239245 s := " "
240246 if len (args ) == 2 {
241247 s = args [1 ].(string )
@@ -312,6 +318,9 @@ var Builtins = []*Function{
312318 {
313319 Name : "repeat" ,
314320 Safe : func (args ... any ) (any , uint , error ) {
321+ if len (args ) < 2 {
322+ return nil , 0 , fmt .Errorf ("not enough arguments to call repeat" )
323+ }
315324 s := args [0 ].(string )
316325 n := runtime .ToInt (args [1 ])
317326 if n < 0 {
@@ -327,6 +336,9 @@ var Builtins = []*Function{
327336 {
328337 Name : "join" ,
329338 Func : func (args ... any ) (any , error ) {
339+ if len (args ) == 0 {
340+ return nil , fmt .Errorf ("not enough arguments to call join" )
341+ }
330342 glue := ""
331343 if len (args ) == 2 {
332344 glue = args [1 ].(string )
@@ -354,27 +366,39 @@ var Builtins = []*Function{
354366 {
355367 Name : "indexOf" ,
356368 Func : func (args ... any ) (any , error ) {
369+ if len (args ) < 2 {
370+ return nil , fmt .Errorf ("not enough arguments to call indexOf" )
371+ }
357372 return strings .Index (args [0 ].(string ), args [1 ].(string )), nil
358373 },
359374 Types : types (strings .Index ),
360375 },
361376 {
362377 Name : "lastIndexOf" ,
363378 Func : func (args ... any ) (any , error ) {
379+ if len (args ) < 2 {
380+ return nil , fmt .Errorf ("not enough arguments to call lastIndexOf" )
381+ }
364382 return strings .LastIndex (args [0 ].(string ), args [1 ].(string )), nil
365383 },
366384 Types : types (strings .LastIndex ),
367385 },
368386 {
369387 Name : "hasPrefix" ,
370388 Func : func (args ... any ) (any , error ) {
389+ if len (args ) < 2 {
390+ return nil , fmt .Errorf ("not enough arguments to call hasPrefix" )
391+ }
371392 return strings .HasPrefix (args [0 ].(string ), args [1 ].(string )), nil
372393 },
373394 Types : types (strings .HasPrefix ),
374395 },
375396 {
376397 Name : "hasSuffix" ,
377398 Func : func (args ... any ) (any , error ) {
399+ if len (args ) < 2 {
400+ return nil , fmt .Errorf ("not enough arguments to call hasSuffix" )
401+ }
378402 return strings .HasSuffix (args [0 ].(string ), args [1 ].(string )), nil
379403 },
380404 Types : types (strings .HasSuffix ),
@@ -436,6 +460,9 @@ var Builtins = []*Function{
436460 {
437461 Name : "toJSON" ,
438462 Func : func (args ... any ) (any , error ) {
463+ if len (args ) == 0 {
464+ return nil , fmt .Errorf ("not enough arguments to call toJSON" )
465+ }
439466 b , err := json .MarshalIndent (args [0 ], "" , " " )
440467 if err != nil {
441468 return nil , err
@@ -447,6 +474,9 @@ var Builtins = []*Function{
447474 {
448475 Name : "fromJSON" ,
449476 Func : func (args ... any ) (any , error ) {
477+ if len (args ) == 0 {
478+ return nil , fmt .Errorf ("not enough arguments to call fromJSON" )
479+ }
450480 var v any
451481 err := json .Unmarshal ([]byte (args [0 ].(string )), & v )
452482 if err != nil {
@@ -459,13 +489,19 @@ var Builtins = []*Function{
459489 {
460490 Name : "toBase64" ,
461491 Func : func (args ... any ) (any , error ) {
492+ if len (args ) == 0 {
493+ return nil , fmt .Errorf ("not enough arguments to call toBase64" )
494+ }
462495 return base64 .StdEncoding .EncodeToString ([]byte (args [0 ].(string ))), nil
463496 },
464497 Types : types (new (func (string ) string )),
465498 },
466499 {
467500 Name : "fromBase64" ,
468501 Func : func (args ... any ) (any , error ) {
502+ if len (args ) == 0 {
503+ return nil , fmt .Errorf ("not enough arguments to call fromBase64" )
504+ }
469505 b , err := base64 .StdEncoding .DecodeString (args [0 ].(string ))
470506 if err != nil {
471507 return nil , err
@@ -505,17 +541,26 @@ var Builtins = []*Function{
505541 {
506542 Name : "duration" ,
507543 Func : func (args ... any ) (any , error ) {
544+ if len (args ) == 0 {
545+ return nil , fmt .Errorf ("not enough arguments to call duration" )
546+ }
508547 return time .ParseDuration (args [0 ].(string ))
509548 },
510549 Types : types (time .ParseDuration ),
511550 },
512551 {
513552 Name : "date" ,
514553 Func : func (args ... any ) (any , error ) {
554+ if len (args ) == 0 {
555+ return nil , fmt .Errorf ("not enough arguments to call date" )
556+ }
515557 tz , ok := args [0 ].(* time.Location )
516558 if ok {
517559 args = args [1 :]
518560 }
561+ if len (args ) == 0 {
562+ return nil , fmt .Errorf ("not enough arguments to call date" )
563+ }
519564
520565 date := args [0 ].(string )
521566 if len (args ) == 2 {
@@ -585,6 +630,9 @@ var Builtins = []*Function{
585630 {
586631 Name : "timezone" ,
587632 Func : func (args ... any ) (any , error ) {
633+ if len (args ) == 0 {
634+ return nil , fmt .Errorf ("not enough arguments to call timezone" )
635+ }
588636 tz , err := time .LoadLocation (args [0 ].(string ))
589637 if err != nil {
590638 return nil , err
@@ -596,6 +644,9 @@ var Builtins = []*Function{
596644 {
597645 Name : "first" ,
598646 Func : func (args ... any ) (any , error ) {
647+ if len (args ) != 1 {
648+ return nil , fmt .Errorf ("invalid number of arguments (expected 1, got %d)" , len (args ))
649+ }
599650 defer func () {
600651 if r := recover (); r != nil {
601652 return
@@ -619,6 +670,9 @@ var Builtins = []*Function{
619670 {
620671 Name : "last" ,
621672 Func : func (args ... any ) (any , error ) {
673+ if len (args ) != 1 {
674+ return nil , fmt .Errorf ("invalid number of arguments (expected 1, got %d)" , len (args ))
675+ }
622676 defer func () {
623677 if r := recover (); r != nil {
624678 return
0 commit comments