@@ -215,7 +215,7 @@ fn template_argument_regex(i: usize) -> Regex {
215
215
fn patch_template_scriptlet ( mut template : String , args : & [ impl AsRef < str > ] ) -> String {
216
216
// `regex` treats `$` as a special character. Instead, `$$` is interpreted as a literal `$`
217
217
// character.
218
- args. iter ( ) . enumerate ( ) . for_each ( |( i, arg) | {
218
+ args. iter ( ) . take ( TEMPLATE_ARGUMENT_RE . len ( ) ) . enumerate ( ) . for_each ( |( i, arg) | {
219
219
template = TEMPLATE_ARGUMENT_RE [ i]
220
220
. replace ( & template, arg. as_ref ( ) . replace ( '$' , "$$" ) )
221
221
. to_string ( ) ;
@@ -559,6 +559,30 @@ mod scriptlet_storage_tests {
559
559
) ;
560
560
}
561
561
562
+ /// Currently, only 9 template arguments are supported - but reaching that limit should not
563
+ /// cause a panic.
564
+ #[ test]
565
+ fn patch_argslist_many_args ( ) {
566
+ let resources = ResourceStorage :: from_resources ( [
567
+ Resource {
568
+ name : "abort-current-script.js" . into ( ) ,
569
+ aliases : vec ! [ "acs.js" . into( ) ] ,
570
+ kind : ResourceType :: Mime ( MimeType :: ApplicationJavascript ) ,
571
+ content : base64:: encode ( "{{1}} {{2}} {{3}} {{4}} {{5}} {{6}} {{7}} {{8}} {{9}} {{10}} {{11}} {{12}}" ) ,
572
+ dependencies : vec ! [ ] ,
573
+ permission : Default :: default ( ) ,
574
+ } ,
575
+ ] ) ;
576
+
577
+ let args = parse_scriptlet_args ( "acs, this, probably, is, going, to, break, brave, and, crash, it, instead, of, ignoring, it" ) ;
578
+ assert_eq ! ( args, vec![ "acs" , "this" , "probably" , "is" , "going" , "to" , "break" , "brave" , "and" , "crash" , "it" , "instead" , "of" , "ignoring" , "it" ] ) ;
579
+
580
+ assert_eq ! (
581
+ resources. get_scriptlet_resource( "acs, this, probably, is, going, to, break, brave, and, crash, it, instead, of, ignoring, it" , Default :: default ( ) ) ,
582
+ Ok ( "this probably is going to break brave and crash {{10}} {{11}} {{12}}" . to_string( ) ) ,
583
+ ) ;
584
+ }
585
+
562
586
#[ test]
563
587
fn permissions ( ) {
564
588
const PERM0 : PermissionMask = PermissionMask :: from_bits ( 0b00000001 ) ;
0 commit comments