Skip to content

Commit c790165

Browse files
committed
add escaped selectors testcase
1 parent 79d565f commit c790165

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

tests/unit/filters/cosmetic.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,60 @@ mod parse_tests {
635635
);
636636
}
637637

638+
#[test]
639+
fn escaped_selectors() {
640+
check_parse_result(
641+
r#"temp-mail.io##.fixed.bottom-0.\[\@media\(max-width\:1350px\)\]\:hidden"#,
642+
CosmeticFilterBreakdown {
643+
selector: SelectorType::PlainCss(
644+
r#".fixed.bottom-0.\[\@media\(max-width\:1350px\)\]\:hidden"#.to_string(),
645+
),
646+
hostnames: Some(vec![2102614015710080174]),
647+
..Default::default()
648+
},
649+
);
650+
check_parse_result(
651+
r#"pinloker.com,sekilastekno.com###main:has(a[\@click="scroll"][target="_blank"]) .entry-content > figure, h3, h4, ol, p, ul"#,
652+
CosmeticFilterBreakdown {
653+
selector: SelectorType::PlainCss(r#"#main:has(a[\@click="scroll"][target="_blank"]) .entry-content > figure, h3, h4, ol, p, ul"#.to_string()),
654+
hostnames: Some(vec![6774884157174391526, 8625775575346486664]),
655+
..Default::default()
656+
}
657+
);
658+
659+
// NOTE: the following `selector` fields are actually invalid selectors, and should keep
660+
// the `\` escape characters from the original rules.
661+
check_parse_result(
662+
r#"pinloker.com,sekilastekno.com##.separator > a[\@click="scroll"][target="_blank"]"#,
663+
CosmeticFilterBreakdown {
664+
selector: SelectorType::PlainCss(
665+
r#".separator > a[@click="scroll"][target="_blank"]"#.to_string(),
666+
),
667+
hostnames: Some(vec![6774884157174391526, 8625775575346486664]),
668+
..Default::default()
669+
},
670+
);
671+
check_parse_result(
672+
r#"senpai-stream.net##div[wire\:click="watching"]:style(display: flex !important;)"#,
673+
CosmeticFilterBreakdown {
674+
selector: SelectorType::PlainCss(r#"div[wire:click="watching"]"#.to_string()),
675+
action: Some(CosmeticFilterAction::Style(
676+
"display: flex !important;".to_string(),
677+
)),
678+
hostnames: Some(vec![12306889736704683473]),
679+
..Default::default()
680+
},
681+
);
682+
check_parse_result(
683+
r#"presearch.com##div[\:class*="AdClass"]"#,
684+
CosmeticFilterBreakdown {
685+
selector: SelectorType::PlainCss(r#"div[:class*="AdClass"]"#.to_string()),
686+
hostnames: Some(vec![15231640029204839219]),
687+
..Default::default()
688+
},
689+
);
690+
}
691+
638692
/// As of writing, these procedural filters with multiple comma-separated selectors aren't
639693
/// fully supported by uBO. Here, they are treated as parsing errors.
640694
#[test]

0 commit comments

Comments
 (0)