Skip to content

Commit 2aaa498

Browse files
committed
remove some filter methods from public API
1 parent 285d056 commit 2aaa498

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/filters/cosmetic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub enum CosmeticFilterOperator {
145145
Xpath(String),
146146
}
147147

148-
pub enum CosmeticFilterLocationType {
148+
pub(crate) enum CosmeticFilterLocationType {
149149
Entity,
150150
NotEntity,
151151
Hostname,
@@ -168,7 +168,7 @@ struct CosmeticFilterLocations {
168168

169169
impl CosmeticFilter {
170170
#[inline]
171-
pub fn locations_before_sharp(
171+
pub(crate) fn locations_before_sharp(
172172
line: &str,
173173
sharp_index: usize,
174174
) -> impl Iterator<Item = (CosmeticFilterLocationType, &str)> {
@@ -524,7 +524,7 @@ fn get_hashes_from_labels(hostname: &str, end: usize, start_of_domain: usize) ->
524524

525525
/// Returns a `Vec` of the hashes of all segments of `hostname` that may match an
526526
/// entity-constrained rule.
527-
pub fn get_entity_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash> {
527+
pub(crate) fn get_entity_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash> {
528528
if let Some((hostname_without_public_suffix, public_suffix)) =
529529
get_hostname_without_public_suffix(hostname, domain)
530530
{
@@ -542,7 +542,7 @@ pub fn get_entity_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash>
542542

543543
/// Returns a `Vec` of the hashes of all segments of `hostname` that may match a
544544
/// hostname-constrained rule.
545-
pub fn get_hostname_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash> {
545+
pub(crate) fn get_hostname_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash> {
546546
get_hashes_from_labels(hostname, hostname.len(), hostname.len() - domain.len())
547547
}
548548

src/filters/network.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::regex_manager::RegexManager;
1414
use crate::request;
1515
use crate::utils::{self, Hash};
1616

17-
pub const TOKENS_BUFFER_SIZE: usize = 200;
17+
pub(crate) const TOKENS_BUFFER_SIZE: usize = 200;
1818

1919
/// For now, only support `$removeparam` with simple alphanumeric/dash/underscore patterns.
2020
static VALID_PARAM: Lazy<Regex> = Lazy::new(|| Regex::new(r"^[a-zA-Z0-9_\-]+$").unwrap());
@@ -1087,6 +1087,16 @@ impl NetworkFilter {
10871087
fn for_https(&self) -> bool {
10881088
self.mask.contains(NetworkFilterMask::FROM_HTTPS)
10891089
}
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+
}
10901100
}
10911101

10921102
impl fmt::Display for NetworkFilter {
@@ -1170,7 +1180,7 @@ fn compute_filter_id(
11701180
/// filters containing at least a * or ^ symbol. Because Regexes are expansive,
11711181
/// we try to convert some patterns to plain filters.
11721182
#[allow(clippy::trivial_regex)]
1173-
pub fn compile_regex(
1183+
pub(crate) fn compile_regex(
11741184
filter: &FilterPart,
11751185
is_right_anchor: bool,
11761186
is_left_anchor: bool,
@@ -1591,24 +1601,14 @@ fn check_pattern(
15911601
}
15921602
}
15931603

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-
16041604
fn check_options(filter: &NetworkFilter, request: &request::Request) -> bool {
16051605
// Bad filter never matches
16061606
if filter.is_badfilter() {
16071607
return false;
16081608
}
16091609
// We first discard requests based on type, protocol and party. This is really
16101610
// cheap and should be done first.
1611-
if !check_cpt_allowed(filter, &request.request_type)
1611+
if !filter.check_cpt_allowed(&request.request_type)
16121612
|| (request.is_https && !filter.for_https())
16131613
|| (request.is_http && !filter.for_http())
16141614
|| (!filter.first_party() && !request.is_third_party)

0 commit comments

Comments
 (0)