Skip to content

Commit

Permalink
return parse error for generic procedural filters
Browse files Browse the repository at this point in the history
  • Loading branch information
antonok-edm committed Nov 28, 2024
1 parent 85ffc76 commit de8e883
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/filters/cosmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum CosmeticFilterError {
GenericUnhide,
#[error("generic script inject")]
GenericScriptInject,
#[error("generic action")]
#[error("procedural and action filters cannot be generic")]
GenericAction,
#[error("double negation")]
DoubleNegation,
Expand Down Expand Up @@ -443,7 +443,7 @@ impl CosmeticFilter {
return Err(CosmeticFilterError::DoubleNegation);
}

Ok(CosmeticFilter {
let this = Self {
entities,
hostnames,
mask,
Expand All @@ -457,7 +457,13 @@ impl CosmeticFilter {
selector,
action,
permission,
})
};

if !this.has_hostname_constraint() && this.plain_css_selector().is_none() {
return Err(CosmeticFilterError::GenericAction);
}

Ok(this)
} else {
Err(CosmeticFilterError::MissingSharp)
}
Expand Down Expand Up @@ -1845,6 +1851,9 @@ mod parse_tests {

// `:has-text` and `:xpath` are now supported procedural filters
assert!(parse_cf("twitter.com##article:has-text(/Promoted|Gesponsert|Реклама|Promocionado/):xpath(../..)").is_ok());

// generic procedural filters are not supported
assert!(parse_cf("##.t-rec > .t886:has-text(cookies)").is_err());
}

#[test]
Expand Down

0 comments on commit de8e883

Please sign in to comment.