@@ -202,6 +202,8 @@ pub enum CbRuleCreationFailure {
202
202
ScriptletInjectionsNotSupported ,
203
203
/// Valid content blocking rules can only include ASCII characters.
204
204
RuleContainsNonASCII ,
205
+ /// `from` as a `domain` alias is not currently supported in content blocking syntax.
206
+ FromNotSupported ,
205
207
}
206
208
207
209
impl TryFrom < ParsedFilter > for CbRuleEquivalent {
@@ -403,8 +405,13 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
403
405
// Unwraps are okay here - any rules with opt_domains or opt_not_domains must have
404
406
// an options section delimited by a '$' character, followed by a `domain=` option.
405
407
let opts = & raw_line[ find_char ( b'$' , raw_line. as_bytes ( ) ) . unwrap ( ) + "$" . len ( ) ..] ;
408
+ let domain_start_index = if let Some ( index) = memmem:: find ( opts. as_bytes ( ) , b"domain=" ) {
409
+ index
410
+ } else {
411
+ return Err ( CbRuleCreationFailure :: FromNotSupported ) ;
412
+ } ;
406
413
let domains_start =
407
- & opts[ memmem :: find ( opts . as_bytes ( ) , b"domain=" ) . unwrap ( ) + "domain=" . len ( ) ..] ;
414
+ & opts[ domain_start_index + "domain=" . len ( ) ..] ;
408
415
let domains = if let Some ( comma) = find_char ( b',' , domains_start. as_bytes ( ) ) {
409
416
& domains_start[ ..comma]
410
417
} else {
@@ -1356,6 +1363,8 @@ mod filterset_tests {
1356
1363
// unicode characters
1357
1364
"||rgmechanics.info/uploads/660х90_" ,
1358
1365
"||insaattrendy.com/Upload/bükerbanner*.jpg" ,
1366
+ // from domain
1367
+ "/siropu/am/core.min.js$script,important,from=~audi-sport.net|~hifiwigwam.com" ,
1359
1368
] , Default :: default ( ) ) ;
1360
1369
1361
1370
let ( cb_rules, used_rules) = set. into_content_blocking ( ) ?;
0 commit comments