Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional CSS validation #62

Merged
merged 2 commits into from Jan 2, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Make CSS validation an optional feature

  • Loading branch information
antonok-edm committed Dec 19, 2019
commit 171a7ebb26c3a2cc3714d26b81459cb8c8154b48
@@ -37,8 +37,8 @@ base64 = "0.10"
rmp-serde = "0.13.7" # rmp-serde 0.14.0 breaks deserialization by changing how enums are deserialized
hashbrown = { version = "0.6", features = ["serde"] }
lifeguard = { version = "0.6", optional = true }
cssparser = "0.25"
selectors = "0.21"
cssparser = { version = "0.25", optional = true }
selectors = { version = "0.21", optional = true }
psl = "0.4.1"

[dev-dependencies]
@@ -81,3 +81,4 @@ full-domain-matching = [] # feature has no explicit dependencies
metrics = []
full-regex-handling = []
object-pooling = ["lifeguard"]
css-validation = ["cssparser", "selectors"]
@@ -20,6 +20,7 @@ pub enum CosmeticFilterError {
GenericScriptInject,
GenericStyle,
DoubleNegation,
EmptyRule,
}

bitflags! {
@@ -207,6 +208,10 @@ impl CosmeticFilter {
};

let mut selector = &line[suffix_start_index..];

if selector.trim().len() == 0 {
return Err(CosmeticFilterError::EmptyRule);
}
let mut style = None;
if line.len() - suffix_start_index > 4 && line[suffix_start_index..].starts_with("+js(") {
if sharp_index == 0 {
@@ -371,6 +376,18 @@ pub fn get_hostname_hashes_from_labels(hostname: &str, domain: &str) -> Vec<Hash
get_hashes_from_labels(hostname, hostname.len(), hostname.len() - domain.len())
}

#[cfg(not(feature="css-validation"))]
mod css_validation {
pub fn is_valid_css_selector(_selector: &str) -> bool {
true
}

pub fn is_valid_css_style(_style: &str) -> bool {
true
}
}

#[cfg(feature="css-validation")]
mod css_validation {
//! Methods for validating CSS selectors and style rules extracted from cosmetic filter rules.
use cssparser::ParserInput;
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.