@@ -248,6 +248,26 @@ var domainFilterTests = []domainFilterTest{
248
248
"exclude" : {".api.example.org" },
249
249
},
250
250
},
251
+ {
252
+ []string {"æøå.org" },
253
+ []string {"api.æøå.org" },
254
+ []string {"foo.api.æøå.org" , "api.æøå.org" },
255
+ false ,
256
+ map [string ][]string {
257
+ "include" : {"æøå.org" },
258
+ "exclude" : {"api.æøå.org" },
259
+ },
260
+ },
261
+ {
262
+ []string {" æøå.org. " },
263
+ []string {" .api.æøå.org " },
264
+ []string {"foo.api.æøå.org" , "bar.baz.api.æøå.org." },
265
+ false ,
266
+ map [string ][]string {
267
+ "include" : {"æøå.org" },
268
+ "exclude" : {".api.æøå.org" },
269
+ },
270
+ },
251
271
{
252
272
[]string {"example.org." },
253
273
[]string {"api.example.org" },
@@ -298,6 +318,16 @@ var domainFilterTests = []domainFilterTest{
298
318
"exclude" : {"foo-bar.example.org" },
299
319
},
300
320
},
321
+ {
322
+ []string {"sTOnks📈.ORG" , "API.xn--StonkS-u354e.ORG" },
323
+ []string {"Foo-Bar.stoNks📈.Org" },
324
+ []string {"FoOoo.Api.Stonks📈.Org" },
325
+ true ,
326
+ map [string ][]string {
327
+ "include" : {"api.stonks📈.org" , "stonks📈.org" },
328
+ "exclude" : {"foo-bar.stonks📈.org" },
329
+ },
330
+ },
301
331
{
302
332
[]string {"eXaMPle.ORG" , "API.example.ORG" },
303
333
[]string {"api.example.org" },
@@ -349,8 +379,27 @@ var regexDomainFilterTests = []regexDomainFilterTest{
349
379
},
350
380
},
351
381
{
352
- regexp .MustCompile (`(?:foo|bar)\.org$` ),
353
- regexp .MustCompile (`^example\.(?:foo|bar)\.org$` ),
382
+ regexp .MustCompile ("(?:😍|🤩)\\ .org$" ),
383
+ regexp .MustCompile ("" ),
384
+ []string {"😍.org" , "xn--r28h.org" , "🤩.org" , "example.😍.org" , "example.🤩.org" , "a.example.xn--r28h.org" , "a.example.🤩.org" },
385
+ true ,
386
+ map [string ]string {
387
+ "regexInclude" : "(?:😍|🤩)\\ .org$" ,
388
+ },
389
+ },
390
+ {
391
+ regexp .MustCompile ("(?:😍|🤩)\\ .org$" ),
392
+ regexp .MustCompile ("^example\\ .(?:😍|🤩)\\ .org$" ),
393
+ []string {"example.😍.org" , "example.🤩.org" },
394
+ false ,
395
+ map [string ]string {
396
+ "regexInclude" : "(?:😍|🤩)\\ .org$" ,
397
+ "regexExclude" : "^example\\ .(?:😍|🤩)\\ .org$" ,
398
+ },
399
+ },
400
+ {
401
+ regexp .MustCompile ("(?:foo|bar)\\ .org$" ),
402
+ regexp .MustCompile ("^example\\ .(?:foo|bar)\\ .org$" ),
354
403
[]string {"foo.org" , "bar.org" , "a.example.foo.org" , "a.example.bar.org" },
355
404
true ,
356
405
map [string ]string {
@@ -480,8 +529,8 @@ func TestPrepareFiltersStripsWhitespaceAndDotSuffix(t *testing.T) {
480
529
nil ,
481
530
},
482
531
{
483
- []string {" foo " , " bar. " , "baz." },
484
- []string {"foo" , "bar" , "baz" },
532
+ []string {" foo " , " bar. " , "baz." , "xn--bar-zna" },
533
+ []string {"foo" , "bar" , "baz" , "øbar" },
485
534
},
486
535
{
487
536
[]string {"foo.bar" , " foo.bar. " , " foo.bar.baz " , " foo.bar.baz. " },
@@ -715,6 +764,24 @@ func TestDomainFilterMatchParent(t *testing.T) {
715
764
"include" : {"a.example.com" , "b.example.com" },
716
765
},
717
766
},
767
+ {
768
+ []string {"a.xn--c1yn36f.æøå." , "b.點看.xn--5cab8c" , "c.點看.æøå" },
769
+ []string {},
770
+ []string {"xn--c1yn36f.xn--5cab8c" },
771
+ true ,
772
+ map [string ][]string {
773
+ "include" : {"a.點看.æøå" , "b.點看.æøå" , "c.點看.æøå" },
774
+ },
775
+ },
776
+ {
777
+ []string {"punycode.xn--c1yn36f.local" , "å.點看.local." , "ø.點看.local" },
778
+ []string {},
779
+ []string {"點看.local" },
780
+ true ,
781
+ map [string ][]string {
782
+ "include" : {"punycode.點看.local" , "å.點看.local" , "ø.點看.local" },
783
+ },
784
+ },
718
785
{
719
786
[]string {"a.example.com" },
720
787
[]string {},
@@ -818,3 +885,67 @@ func TestSimpleDomainFilterWithExclusion(t *testing.T) {
818
885
})
819
886
}
820
887
}
888
+
889
+ func TestDomainFilterNormalizeDomain (t * testing.T ) {
890
+ records := []struct {
891
+ dnsName string
892
+ expect string
893
+ }{
894
+ {
895
+ "3AAAA.FOO.BAR.COM" ,
896
+ "3aaaa.foo.bar.com" ,
897
+ },
898
+ {
899
+ "example.foo.com." ,
900
+ "example.foo.com" ,
901
+ },
902
+ {
903
+ "example123.foo.com" ,
904
+ "example123.foo.com" ,
905
+ },
906
+ {
907
+ "foo.com." ,
908
+ "foo.com" ,
909
+ },
910
+ {
911
+ "foo123.COM" ,
912
+ "foo123.com" ,
913
+ },
914
+ {
915
+ "my-exaMple3.FOO.BAR.COM" ,
916
+ "my-example3.foo.bar.com" ,
917
+ },
918
+ {
919
+ "my-example1214.FOO-1235.BAR-foo.COM" ,
920
+ "my-example1214.foo-1235.bar-foo.com" ,
921
+ },
922
+ {
923
+ "my-example-my-example-1214.FOO-1235.BAR-foo.COM" ,
924
+ "my-example-my-example-1214.foo-1235.bar-foo.com" ,
925
+ },
926
+ {
927
+ "xn--c1yn36f.org." ,
928
+ "點看.org" ,
929
+ },
930
+ {
931
+ "xn--nordic--w1a.xn--xn--kItty-pd34d-hn01b3542b.com" ,
932
+ "nordic-ø.xn--kitty-點看pd34d.com" ,
933
+ },
934
+ {
935
+ "xn--nordic--w1a.xn--kItty-pd34d.com" ,
936
+ "nordic-ø.kitty😸.com" ,
937
+ },
938
+ {
939
+ "nordic-ø.kitty😸.COM" ,
940
+ "nordic-ø.kitty😸.com" ,
941
+ },
942
+ {
943
+ "xn--nordic--w1a.kiTTy😸.com." ,
944
+ "nordic-ø.kitty😸.com" ,
945
+ },
946
+ }
947
+ for _ , r := range records {
948
+ gotName := normalizeDomain (r .dnsName )
949
+ assert .Equal (t , r .expect , gotName )
950
+ }
951
+ }
0 commit comments