Skip to content

Commit

Permalink
fix(parser/html): check void element names case insensitively
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Sep 17, 2024
1 parent 1fe6f78 commit cf87aa4
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 2 deletions.
8 changes: 6 additions & 2 deletions crates/biome_html_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ fn parse_element(p: &mut HtmlParser) -> ParsedSyntax {

p.bump(T![<]);
let opening_tag_name = p.cur_text().to_string();
let should_be_self_closing = VOID_ELEMENTS.contains(&opening_tag_name.as_str());
let should_be_self_closing = VOID_ELEMENTS
.iter()
.any(|tag| tag.eq_ignore_ascii_case(opening_tag_name.as_str()));
parse_literal(p).or_add_diagnostic(p, expected_element_name);

AttributeList.parse_list(p);
Expand Down Expand Up @@ -106,7 +108,9 @@ fn parse_closing_element(p: &mut HtmlParser) -> ParsedSyntax {
let m = p.start();
p.bump(T![<]);
p.bump(T![/]);
let should_be_self_closing = VOID_ELEMENTS.contains(&p.cur_text());
let should_be_self_closing = VOID_ELEMENTS
.iter()
.any(|tag| tag.eq_ignore_ascii_case(p.cur_text()));
if should_be_self_closing {
p.error(void_element_should_not_have_closing_tag(p, p.cur_range()).into_diagnostic(p));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<head>
<META charset="utf-8">
<MeTa charset="utf-8">
</head>
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```html
<head>
<META charset="utf-8">
<MeTa charset="utf-8">
</head>
```
## AST
```
HtmlRoot {
bom_token: missing (optional),
directive: missing (optional),
html: HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@0..1 "<" [] [],
name: HtmlName {
value_token: HTML_LITERAL@1..5 "head" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@5..6 ">" [] [],
},
children: HtmlElementList [
HtmlSelfClosingElement {
l_angle_token: L_ANGLE@6..9 "<" [Newline("\n"), Whitespace("\t")] [],
name: HtmlName {
value_token: HTML_LITERAL@9..14 "META" [] [Whitespace(" ")],
},
attributes: HtmlAttributeList [
HtmlAttribute {
name: HtmlName {
value_token: HTML_LITERAL@14..21 "charset" [] [],
},
initializer: HtmlAttributeInitializerClause {
eq_token: EQ@21..22 "=" [] [],
value: HtmlString {
value_token: HTML_STRING_LITERAL@22..29 "\"utf-8\"" [] [],
},
},
},
],
slash_token: missing (optional),
r_angle_token: R_ANGLE@29..30 ">" [] [],
},
HtmlSelfClosingElement {
l_angle_token: L_ANGLE@30..33 "<" [Newline("\n"), Whitespace("\t")] [],
name: HtmlName {
value_token: HTML_LITERAL@33..38 "MeTa" [] [Whitespace(" ")],
},
attributes: HtmlAttributeList [
HtmlAttribute {
name: HtmlName {
value_token: HTML_LITERAL@38..45 "charset" [] [],
},
initializer: HtmlAttributeInitializerClause {
eq_token: EQ@45..46 "=" [] [],
value: HtmlString {
value_token: HTML_STRING_LITERAL@46..53 "\"utf-8\"" [] [],
},
},
},
],
slash_token: missing (optional),
r_angle_token: R_ANGLE@53..54 ">" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@54..56 "<" [Newline("\n")] [],
slash_token: SLASH@56..57 "/" [] [],
name: HtmlName {
value_token: HTML_LITERAL@57..61 "head" [] [],
},
r_angle_token: R_ANGLE@61..62 ">" [] [],
},
},
eof_token: EOF@62..63 "" [Newline("\n")] [],
}
```
## CST
```
0: [email protected]
0: (empty)
1: (empty)
2: [email protected]
0: [email protected]
0: [email protected] "<" [] []
1: [email protected]
0: [email protected] "head" [] []
2: [email protected]
3: [email protected] ">" [] []
1: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t")] []
1: [email protected]
0: [email protected] "META" [] [Whitespace(" ")]
2: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "charset" [] []
1: [email protected]
0: [email protected] "=" [] []
1: [email protected]
0: [email protected] "\"utf-8\"" [] []
3: (empty)
4: [email protected] ">" [] []
1: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t")] []
1: [email protected]
0: [email protected] "MeTa" [] [Whitespace(" ")]
2: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "charset" [] []
1: [email protected]
0: [email protected] "=" [] []
1: [email protected]
0: [email protected] "\"utf-8\"" [] []
3: (empty)
4: [email protected] ">" [] []
2: [email protected]
0: [email protected] "<" [Newline("\n")] []
1: [email protected] "/" [] []
2: [email protected]
0: [email protected] "head" [] []
3: [email protected] ">" [] []
3: [email protected] "" [Newline("\n")] []
```

0 comments on commit cf87aa4

Please sign in to comment.