Skip to content

Commit f8ae9ef

Browse files
committed
update docs for constant "NetworkFilter" string with debug disabled
1 parent cb0dd04 commit f8ae9ef

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

src/blocker.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,18 @@ pub struct BlockerResult {
5151
/// modified at all, the new version will be here. This should be used
5252
/// as long as the request is not blocked.
5353
pub rewritten_url: Option<String>,
54-
/// Exception is `Some` when the blocker matched on an exception rule.
54+
/// Contains a string representation of any matched exception rule.
5555
/// Effectively this means that there was a match, but the request should
56-
/// not be blocked. It is a non-empty string if the blocker was initialized
57-
/// from a list of rules with debugging enabled, otherwise the original
58-
/// string representation is discarded to reduce memory use.
56+
/// not be blocked.
57+
///
58+
/// If debugging was _not_ enabled (see [`crate::FilterSet::new`]), this
59+
/// will only contain a constant `"NetworkFilter"` placeholder string.
5960
pub exception: Option<String>,
60-
/// Filter--similarly to exception--includes the string representation of
61-
/// the rule when there is a match and debugging is enabled. Otherwise, on
62-
/// a match, it is `Some`.
61+
/// When `matched` is true, this contains a string representation of the
62+
/// matched blocking rule.
63+
///
64+
/// If debugging was _not_ enabled (see [`crate::FilterSet::new`]), this
65+
/// will only contain a constant `"NetworkFilter"` placeholder string.
6366
pub filter: Option<String>,
6467
}
6568

@@ -2119,6 +2122,19 @@ fn test_removeparam_same_tokens() {
21192122
}
21202123
}
21212124

2125+
#[cfg(test)]
2126+
mod placeholder_string_tests {
2127+
/// If this changes, be sure to update the documentation for [`BlockerResult`] as well.
2128+
#[test]
2129+
fn test_constant_placeholder_string() {
2130+
let mut filter_set = crate::lists::FilterSet::new(false);
2131+
filter_set.add_filter("||example.com^", Default::default()).unwrap();
2132+
let engine = crate::Engine::from_filter_set(filter_set, true);
2133+
let block = engine.check_network_request(&crate::request::Request::new("https://example.com", "https://example.com", "document").unwrap());
2134+
assert_eq!(block.filter, Some("NetworkFilter".to_string()));
2135+
}
2136+
}
2137+
21222138
#[cfg(test)]
21232139
mod legacy_rule_parsing_tests {
21242140
use crate::test_utils::rules_from_lists;

0 commit comments

Comments
 (0)