@@ -202,6 +202,8 @@ pub enum CbRuleCreationFailure {
202202 ScriptletInjectionsNotSupported ,
203203 /// Valid content blocking rules can only include ASCII characters.
204204 RuleContainsNonASCII ,
205+ /// `from` as a `domain` alias is not currently supported in content blocking syntax.
206+ FromNotSupported ,
205207}
206208
207209impl TryFrom < ParsedFilter > for CbRuleEquivalent {
@@ -403,8 +405,13 @@ impl TryFrom<NetworkFilter> for CbRuleEquivalent {
403405 // Unwraps are okay here - any rules with opt_domains or opt_not_domains must have
404406 // an options section delimited by a '$' character, followed by a `domain=` option.
405407 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+ } ;
406413 let domains_start =
407- & opts[ memmem :: find ( opts . as_bytes ( ) , b"domain=" ) . unwrap ( ) + "domain=" . len ( ) ..] ;
414+ & opts[ domain_start_index + "domain=" . len ( ) ..] ;
408415 let domains = if let Some ( comma) = find_char ( b',' , domains_start. as_bytes ( ) ) {
409416 & domains_start[ ..comma]
410417 } else {
@@ -1356,6 +1363,8 @@ mod filterset_tests {
13561363 // unicode characters
13571364 "||rgmechanics.info/uploads/660х90_" ,
13581365 "||insaattrendy.com/Upload/bükerbanner*.jpg" ,
1366+ // from domain
1367+ "/siropu/am/core.min.js$script,important,from=~audi-sport.net|~hifiwigwam.com" ,
13591368 ] , Default :: default ( ) ) ;
13601369
13611370 let ( cb_rules, used_rules) = set. into_content_blocking ( ) ?;
0 commit comments