fix(linter): panic on invalid lang in a11y/lang. (#4630)

fixes #4629
This commit is contained in:
rzvxa 2024-08-05 01:15:39 +00:00
parent 439ce5bc85
commit 94440ad35f
2 changed files with 9 additions and 2 deletions

View file

@ -94,8 +94,7 @@ fn is_valid_lang_prop(item: &JSXAttributeItem) -> bool {
!container.expression.is_expression() || !container.expression.is_undefined()
}
Some(JSXAttributeValue::StringLiteral(str)) => {
let language_tag = LanguageTag::parse(str.value.as_str()).unwrap();
language_tag.is_valid()
LanguageTag::parse(str.value.as_str()).as_ref().is_ok_and(LanguageTag::is_valid)
}
_ => true,
}
@ -135,6 +134,7 @@ fn test() {
let fail = vec![
("<html lang='foo' />", None, None, None),
("<html lang='n'></html>", None, None, None),
("<html lang='zz-LL' />", None, None, None),
("<html lang={undefined} />", None, None, None),
("<Foo lang={undefined} />", None, Some(settings()), None),

View file

@ -8,6 +8,13 @@ source: crates/oxc_linter/src/tester.rs
╰────
help: Set a valid value for lang attribute.
⚠ eslint-plugin-jsx-a11y(lang): Lang attribute must have a valid value.
╭─[lang.tsx:1:7]
1 │ <html lang='n'></html>
· ────────
╰────
help: Set a valid value for lang attribute.
⚠ eslint-plugin-jsx-a11y(lang): Lang attribute must have a valid value.
╭─[lang.tsx:1:7]
1 │ <html lang='zz-LL' />