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 f2b3273 commit 7967237
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,8 @@ impl Rule for PreferDomNodeDataset {
}
}

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 7967237

Please sign in to comment.