@@ -550,6 +550,35 @@ func TestParseJson(t *testing.T) {
550
550
}
551
551
}
552
552
553
+ func TestQueryEscape (t * testing.T ) {
554
+ tests := []struct {
555
+ tmpl string
556
+ context interface {}
557
+ expected string
558
+ }{
559
+ {`{{queryEscape .}}` , `example.com` , `example.com` },
560
+ {`{{queryEscape .}}` , `.example.com` , `.example.com` },
561
+ {`{{queryEscape .}}` , `*.example.com` , `%2A.example.com` },
562
+ {`{{queryEscape .}}` , `~^example\.com(\..*\.xip\.io)?$` , `~%5Eexample%5C.com%28%5C..%2A%5C.xip%5C.io%29%3F%24` },
563
+ }
564
+
565
+ for n , test := range tests {
566
+ tmplName := fmt .Sprintf ("queryEscape-test-%d" , n )
567
+ tmpl := template .Must (newTemplate (tmplName ).Parse (test .tmpl ))
568
+
569
+ var b bytes.Buffer
570
+ err := tmpl .ExecuteTemplate (& b , tmplName , test .context )
571
+ if err != nil {
572
+ t .Fatalf ("Error executing template: %v" , err )
573
+ }
574
+
575
+ got := b .String ()
576
+ if test .expected != got {
577
+ t .Fatalf ("Incorrect output found; expected %s, got %s" , test .expected , got )
578
+ }
579
+ }
580
+ }
581
+
553
582
func TestArrayClosestExact (t * testing.T ) {
554
583
if arrayClosest ([]string {"foo.bar.com" , "bar.com" }, "foo.bar.com" ) != "foo.bar.com" {
555
584
t .Fatal ("Expected foo.bar.com" )
0 commit comments