@@ -14,7 +14,7 @@ use crate::regex_manager::RegexManager;
14
14
use crate :: request;
15
15
use crate :: utils:: { self , Hash } ;
16
16
17
- pub const TOKENS_BUFFER_SIZE : usize = 200 ;
17
+ pub ( crate ) const TOKENS_BUFFER_SIZE : usize = 200 ;
18
18
19
19
/// For now, only support `$removeparam` with simple alphanumeric/dash/underscore patterns.
20
20
static VALID_PARAM : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"^[a-zA-Z0-9_\-]+$" ) . unwrap ( ) ) ;
@@ -1087,6 +1087,16 @@ impl NetworkFilter {
1087
1087
fn for_https ( & self ) -> bool {
1088
1088
self . mask . contains ( NetworkFilterMask :: FROM_HTTPS )
1089
1089
}
1090
+
1091
+ fn check_cpt_allowed ( & self , cpt : & request:: RequestType ) -> bool {
1092
+ match NetworkFilterMask :: from ( cpt) {
1093
+ // TODO this is not ideal, but required to allow regexed exception rules without an
1094
+ // explicit `$document` option to apply uBO-style.
1095
+ // See also: https://github.com/uBlockOrigin/uBlock-issues/issues/1501
1096
+ NetworkFilterMask :: FROM_DOCUMENT => self . mask . contains ( NetworkFilterMask :: FROM_DOCUMENT ) || self . is_exception ( ) ,
1097
+ mask => self . mask . contains ( mask) ,
1098
+ }
1099
+ }
1090
1100
}
1091
1101
1092
1102
impl fmt:: Display for NetworkFilter {
@@ -1170,7 +1180,7 @@ fn compute_filter_id(
1170
1180
/// filters containing at least a * or ^ symbol. Because Regexes are expansive,
1171
1181
/// we try to convert some patterns to plain filters.
1172
1182
#[ allow( clippy:: trivial_regex) ]
1173
- pub fn compile_regex (
1183
+ pub ( crate ) fn compile_regex (
1174
1184
filter : & FilterPart ,
1175
1185
is_right_anchor : bool ,
1176
1186
is_left_anchor : bool ,
@@ -1591,24 +1601,14 @@ fn check_pattern(
1591
1601
}
1592
1602
}
1593
1603
1594
- pub fn check_cpt_allowed ( filter : & NetworkFilter , cpt : & request:: RequestType ) -> bool {
1595
- match NetworkFilterMask :: from ( cpt) {
1596
- // TODO this is not ideal, but required to allow regexed exception rules without an
1597
- // explicit `$document` option to apply uBO-style.
1598
- // See also: https://github.com/uBlockOrigin/uBlock-issues/issues/1501
1599
- NetworkFilterMask :: FROM_DOCUMENT => filter. mask . contains ( NetworkFilterMask :: FROM_DOCUMENT ) || filter. is_exception ( ) ,
1600
- mask => filter. mask . contains ( mask) ,
1601
- }
1602
- }
1603
-
1604
1604
fn check_options ( filter : & NetworkFilter , request : & request:: Request ) -> bool {
1605
1605
// Bad filter never matches
1606
1606
if filter. is_badfilter ( ) {
1607
1607
return false ;
1608
1608
}
1609
1609
// We first discard requests based on type, protocol and party. This is really
1610
1610
// cheap and should be done first.
1611
- if !check_cpt_allowed ( filter , & request. request_type )
1611
+ if !filter . check_cpt_allowed ( & request. request_type )
1612
1612
|| ( request. is_https && !filter. for_https ( ) )
1613
1613
|| ( request. is_http && !filter. for_http ( ) )
1614
1614
|| ( !filter. first_party ( ) && !request. is_third_party )
0 commit comments