Skip to content

Commit

Permalink
fix(linter): fix panic with unicode in unicorn/prefer_dom_node_dataset (
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jul 10, 2024
1 parent 2203143 commit c8f5664
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,25 @@ impl Rule for PreferDomNodeDataset {

match method_name {
"setAttribute" => {
ctx.diagnostic(set(span, &dataset_property_name));
ctx.diagnostic(set(span, dataset_property_name));
}
"getAttribute" => {
ctx.diagnostic(get(span, &dataset_property_name));
ctx.diagnostic(get(span, dataset_property_name));
}

"removeAttribute" => ctx.diagnostic(remove(string_lit.span, &dataset_property_name)),
"removeAttribute" => ctx.diagnostic(remove(string_lit.span, dataset_property_name)),

"hasAttribute" => {
ctx.diagnostic(has(span, &dataset_property_name));
ctx.diagnostic(has(span, dataset_property_name));
}

_ => unreachable!(),
}
}
}

fn strip_data_prefix(s: &str) -> Option<String> {
let prefix = "data-";
if s.len() >= prefix.len() && s[..prefix.len()].eq_ignore_ascii_case(prefix) {
Some(s[prefix.len()..].to_string())
} else {
None
}
fn strip_data_prefix(s: &str) -> Option<&str> {
s.strip_prefix("data-").or_else(|| s.strip_prefix("DATA-"))
}

#[test]
Expand Down Expand Up @@ -184,6 +179,7 @@ fn test() {
r"element.getAttribute(0);",
r#"element.getAttribute("foo-unicorn");"#,
r#"element.getAttribute("data");"#,
r#"element.getAttribute("stylý");"#,
];

let fail = vec![
Expand Down

0 comments on commit c8f5664

Please sign in to comment.