Skip to content

Commit c8f5664

Browse files
committed
fix(linter): fix panic with unicode in unicorn/prefer_dom_node_dataset (#4166)
1 parent 2203143 commit c8f5664

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

crates/oxc_linter/src/rules/unicorn/prefer_dom_node_dataset.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,25 @@ impl Rule for PreferDomNodeDataset {
9595

9696
match method_name {
9797
"setAttribute" => {
98-
ctx.diagnostic(set(span, &dataset_property_name));
98+
ctx.diagnostic(set(span, dataset_property_name));
9999
}
100100
"getAttribute" => {
101-
ctx.diagnostic(get(span, &dataset_property_name));
101+
ctx.diagnostic(get(span, dataset_property_name));
102102
}
103103

104-
"removeAttribute" => ctx.diagnostic(remove(string_lit.span, &dataset_property_name)),
104+
"removeAttribute" => ctx.diagnostic(remove(string_lit.span, dataset_property_name)),
105105

106106
"hasAttribute" => {
107-
ctx.diagnostic(has(span, &dataset_property_name));
107+
ctx.diagnostic(has(span, dataset_property_name));
108108
}
109109

110110
_ => unreachable!(),
111111
}
112112
}
113113
}
114114

115-
fn strip_data_prefix(s: &str) -> Option<String> {
116-
let prefix = "data-";
117-
if s.len() >= prefix.len() && s[..prefix.len()].eq_ignore_ascii_case(prefix) {
118-
Some(s[prefix.len()..].to_string())
119-
} else {
120-
None
121-
}
115+
fn strip_data_prefix(s: &str) -> Option<&str> {
116+
s.strip_prefix("data-").or_else(|| s.strip_prefix("DATA-"))
122117
}
123118

124119
#[test]
@@ -184,6 +179,7 @@ fn test() {
184179
r"element.getAttribute(0);",
185180
r#"element.getAttribute("foo-unicorn");"#,
186181
r#"element.getAttribute("data");"#,
182+
r#"element.getAttribute("stylý");"#,
187183
];
188184

189185
let fail = vec![

0 commit comments

Comments
 (0)