@@ -1616,7 +1616,7 @@ mod blocker_tests {
1616
1616
"*$removeparam=fbclid" ,
1617
1617
"/script.js$redirect-rule=noopjs" ,
1618
1618
"^block^$important" ,
1619
- "$removeparam=testCase,~image " ,
1619
+ "$removeparam=testCase,~xhr " ,
1620
1620
] ;
1621
1621
1622
1622
let ( network_filters, _) = parse_filters ( & filters, true , Default :: default ( ) ) ;
@@ -1630,73 +1630,89 @@ mod blocker_tests {
1630
1630
1631
1631
resources. add_resource ( Resource :: simple ( "noopjs" , crate :: resources:: MimeType :: ApplicationJavascript , "(() => {})()" ) ) . unwrap ( ) ;
1632
1632
1633
- let result = blocker. check ( & Request :: new ( "https://example.com?q=1&test=2#blue" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1633
+ let result = blocker. check ( & Request :: new ( "https://example.com?q=1&test=2#blue" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1634
1634
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q=1#blue" . into( ) ) ) ;
1635
1635
assert ! ( !result. matched) ;
1636
1636
1637
- let result = blocker. check ( & Request :: new ( "https://example.com?test=2&q=1#blue" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1637
+ let result = blocker. check ( & Request :: new ( "https://example.com?test=2&q=1#blue" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1638
1638
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q=1#blue" . into( ) ) ) ;
1639
1639
assert ! ( !result. matched) ;
1640
1640
1641
- let result = blocker. check ( & Request :: new ( "https://example.com?test=2#blue" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1641
+ let result = blocker. check ( & Request :: new ( "https://example.com?test=2#blue" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1642
1642
assert_eq ! ( result. rewritten_url, Some ( "https://example.com#blue" . into( ) ) ) ;
1643
1643
assert ! ( !result. matched) ;
1644
1644
1645
- let result = blocker. check ( & Request :: new ( "https://example.com?q=1#blue" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1645
+ let result = blocker. check ( & Request :: new ( "https://example.com?q=1#blue" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1646
1646
assert_eq ! ( result. rewritten_url, None ) ;
1647
1647
assert ! ( !result. matched) ;
1648
1648
1649
- let result = blocker. check ( & Request :: new ( "https://example.com?q=1&test=2" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1649
+ let result = blocker. check ( & Request :: new ( "https://example.com?q=1&test=2" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1650
1650
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q=1" . into( ) ) ) ;
1651
1651
assert ! ( !result. matched) ;
1652
1652
1653
- let result = blocker. check ( & Request :: new ( "https://example.com?test=2&q=1" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1653
+ let result = blocker. check ( & Request :: new ( "https://example.com?test=2&q=1" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1654
1654
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q=1" . into( ) ) ) ;
1655
1655
assert ! ( !result. matched) ;
1656
1656
1657
- let result = blocker. check ( & Request :: new ( "https://example.com?test=2" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1657
+ let result = blocker. check ( & Request :: new ( "https://example.com?test=2" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1658
1658
assert_eq ! ( result. rewritten_url, Some ( "https://example.com" . into( ) ) ) ;
1659
1659
assert ! ( !result. matched) ;
1660
1660
1661
- let result = blocker. check ( & Request :: new ( "https://example.com?q=1 " , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1661
+ let result = blocker. check ( & Request :: new ( "https://example.com?test=2 " , "https://antonok.com" , "image " ) . unwrap ( ) , & resources) ;
1662
1662
assert_eq ! ( result. rewritten_url, None ) ;
1663
1663
assert ! ( !result. matched) ;
1664
1664
1665
- let result = blocker. check ( & Request :: new ( "https://example.com?q=fbclid " , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1665
+ let result = blocker. check ( & Request :: new ( "https://example.com?q=1 " , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1666
1666
assert_eq ! ( result. rewritten_url, None ) ;
1667
1667
assert ! ( !result. matched) ;
1668
1668
1669
- let result = blocker. check ( & Request :: new ( "https://example.com?fbclid=10938&q=1&test=2" , "https://antonok.com" , "script" ) . unwrap ( ) , & resources) ;
1669
+ let result = blocker. check ( & Request :: new ( "https://example.com?q=fbclid" , "https://antonok.com" , "xhr" ) . unwrap ( ) , & resources) ;
1670
+ assert_eq ! ( result. rewritten_url, None ) ;
1671
+ assert ! ( !result. matched) ;
1672
+
1673
+ let result = blocker. check ( & Request :: new ( "https://example.com?fbclid=10938&q=1&test=2" , "https://antonok.com" , "xhr" ) . unwrap ( ) , & resources) ;
1670
1674
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q=1" . into( ) ) ) ;
1671
1675
assert ! ( !result. matched) ;
1672
1676
1673
- let result = blocker. check ( & Request :: new ( "https://test.com?fbclid=10938&q=1&test=2" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1677
+ let result = blocker. check ( & Request :: new ( "https://test.com?fbclid=10938&q=1&test=2" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1674
1678
assert_eq ! ( result. rewritten_url, Some ( "https://test.com?q=1&test=2" . into( ) ) ) ;
1675
1679
assert ! ( !result. matched) ;
1676
1680
1677
- let result = blocker. check ( & Request :: new ( "https://example.com?q1=1&q2=2&q3=3&test=2&q4=4&q5=5&fbclid=39" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1681
+ let result = blocker. check ( & Request :: new ( "https://example.com?q1=1&q2=2&q3=3&test=2&q4=4&q5=5&fbclid=39" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1678
1682
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q1=1&q2=2&q3=3&q4=4&q5=5" . into( ) ) ) ;
1679
1683
assert ! ( !result. matched) ;
1680
1684
1681
- let result = blocker. check ( & Request :: new ( "https://example.com?q1=1&q1=2&test=2&test=3" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1685
+ let result = blocker. check ( & Request :: new ( "https://example.com?q1=1&q1=2&test=2&test=3" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1682
1686
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?q1=1&q1=2" . into( ) ) ) ;
1683
1687
assert ! ( !result. matched) ;
1684
1688
1685
- let result = blocker. check ( & Request :: new ( "https://example.com/script.js?test=2#blue" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1689
+ let result = blocker. check ( & Request :: new ( "https://example.com/script.js?test=2#blue" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1686
1690
assert_eq ! ( result. rewritten_url, Some ( "https://example.com/script.js#blue" . into( ) ) ) ;
1687
1691
assert_eq ! ( result. redirect, Some ( "data:application/javascript;base64,KCgpID0+IHt9KSgp" . into( ) ) ) ;
1688
1692
assert ! ( !result. matched) ;
1689
1693
1690
- let result = blocker. check ( & Request :: new ( "https://example.com/block/script.js?test=2" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1694
+ let result = blocker. check ( & Request :: new ( "https://example.com/block/script.js?test=2" , "https://antonok.com" , "xhr " ) . unwrap ( ) , & resources) ;
1691
1695
assert_eq ! ( result. rewritten_url, None ) ;
1692
1696
assert_eq ! ( result. redirect, Some ( "data:application/javascript;base64,KCgpID0+IHt9KSgp" . into( ) ) ) ;
1693
1697
assert ! ( result. matched) ;
1694
1698
1695
- let result = blocker. check ( & Request :: new ( "https://example.com/Path/?Test=ABC&testcase=AbC&testCase=aBc" , "https://antonok.com" , "script" ) . unwrap ( ) , & resources) ;
1699
+ let result = blocker. check ( & Request :: new ( "https://example.com/Path/?Test=ABC&testcase=AbC&testCase=aBc" , "https://antonok.com" , "xhr" ) . unwrap ( ) , & resources) ;
1700
+ assert_eq ! ( result. rewritten_url, None ) ;
1701
+ assert ! ( !result. matched) ;
1702
+
1703
+ let result = blocker. check ( & Request :: new ( "https://example.com/Path/?Test=ABC&testcase=AbC&testCase=aBc" , "https://antonok.com" , "image" ) . unwrap ( ) , & resources) ;
1704
+ assert_eq ! ( result. rewritten_url, None ) ;
1705
+ assert ! ( !result. matched) ;
1706
+
1707
+ let result = blocker. check ( & Request :: new ( "https://example.com/Path/?Test=ABC&testcase=AbC&testCase=aBc" , "https://antonok.com" , "subdocument" ) . unwrap ( ) , & resources) ;
1708
+ assert_eq ! ( result. rewritten_url, Some ( "https://example.com/Path/?Test=ABC&testcase=AbC" . into( ) ) ) ;
1709
+ assert ! ( !result. matched) ;
1710
+
1711
+ let result = blocker. check ( & Request :: new ( "https://example.com/Path/?Test=ABC&testcase=AbC&testCase=aBc" , "https://antonok.com" , "document" ) . unwrap ( ) , & resources) ;
1696
1712
assert_eq ! ( result. rewritten_url, Some ( "https://example.com/Path/?Test=ABC&testcase=AbC" . into( ) ) ) ;
1697
1713
assert ! ( !result. matched) ;
1698
1714
1699
- let result = blocker. check ( & Request :: new ( "https://example.com?Test=ABC?123&test=3#&test=4#b" , "https://antonok.com" , "script " ) . unwrap ( ) , & resources) ;
1715
+ let result = blocker. check ( & Request :: new ( "https://example.com?Test=ABC?123&test=3#&test=4#b" , "https://antonok.com" , "document " ) . unwrap ( ) , & resources) ;
1700
1716
assert_eq ! ( result. rewritten_url, Some ( "https://example.com?Test=ABC?123#&test=4#b" . into( ) ) ) ;
1701
1717
assert ! ( !result. matched) ;
1702
1718
@@ -1774,7 +1790,7 @@ mod blocker_tests {
1774
1790
let resources = ResourceStorage :: default ( ) ;
1775
1791
1776
1792
for ( original, expected) in testcases. into_iter ( ) {
1777
- let result = blocker. check ( & Request :: new ( original, "https://example.net" , "script " ) . unwrap ( ) , & resources) ;
1793
+ let result = blocker. check ( & Request :: new ( original, "https://example.net" , "xhr " ) . unwrap ( ) , & resources) ;
1778
1794
let expected = if original == expected {
1779
1795
None
1780
1796
} else {
@@ -1799,7 +1815,7 @@ fn test_removeparam_same_tokens() {
1799
1815
1800
1816
let blocker = Blocker :: new ( network_filters, & blocker_options) ;
1801
1817
1802
- let result = blocker. check ( & Request :: new ( "https://example.com?example1_=1&example1-=2" , "https://example.com" , "script " ) . unwrap ( ) , & Default :: default ( ) ) ;
1818
+ let result = blocker. check ( & Request :: new ( "https://example.com?example1_=1&example1-=2" , "https://example.com" , "xhr " ) . unwrap ( ) , & Default :: default ( ) ) ;
1803
1819
assert_eq ! ( result. rewritten_url, Some ( "https://example.com" . into( ) ) ) ;
1804
1820
assert ! ( !result. matched) ;
1805
1821
}
0 commit comments