mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(linter): fix panic with unicode in unicorn/prefer_dom_node_dataset (#4166)
This commit is contained in:
parent
22031430b1
commit
c8f5664e0a
1 changed files with 7 additions and 11 deletions
|
|
@ -95,16 +95,16 @@ 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!(),
|
||||
|
|
@ -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]
|
||||
|
|
@ -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![
|
||||
|
|
|
|||
Loading…
Reference in a new issue