Skip to content

Commit

Permalink
fix(parser/html): fix incorrect parsing when text starts with a quote
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed Sep 20, 2024
1 parent d137533 commit b7a77c2
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 24 deletions.
2 changes: 1 addition & 1 deletion crates/biome_html_parser/src/syntax/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn parse_closing_element(p: &mut HtmlParser) -> ParsedSyntax {
p.error(void_element_should_not_have_closing_tag(p, p.cur_range()).into_diagnostic(p));
}
let _name = parse_literal(p);
p.bump(T![>]);
p.bump_with_context(T![>], HtmlLexContext::OutsideTag);
Present(m.complete(p, HTML_CLOSING_ELEMENT))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ HtmlRoot {
},
},
HtmlContent {
value_token: HTML_LITERAL@38..46 "some" [Newline("\n"), Whitespace("\t\t")] [Whitespace(" ")],
},
HtmlContent {
value_token: HTML_LITERAL@46..50 "text" [] [],
value_token: HTML_LITERAL@38..50 "some text" [Newline("\n"), Whitespace("\t\t")] [],
},
HtmlElement {
opening_element: HtmlOpeningElement {
Expand Down Expand Up @@ -419,11 +416,9 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
2: [email protected]
0: [email protected] "some" [Newline("\n"), Whitespace("\t\t")] [Whitespace(" ")]
3: [email protected]
0: [email protected] "text" [] []
4: [email protected]
2: [email protected]
0: [email protected] "some text" [Newline("\n"), Whitespace("\t\t")] []
3: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t\t")] []
1: [email protected]
Expand All @@ -437,7 +432,7 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
5: [email protected]
4: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t\t")] []
1: [email protected]
Expand All @@ -451,7 +446,7 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
6: [email protected]
5: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t\t")] []
1: [email protected]
Expand All @@ -465,7 +460,7 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
7: [email protected]
6: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n"), Whitespace("\t\t")] []
1: [email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ HtmlRoot {
},
},
HtmlContent {
value_token: HTML_LITERAL@21..27 "some" [Newline("\n")] [Whitespace(" ")],
},
HtmlContent {
value_token: HTML_LITERAL@27..31 "text" [] [],
value_token: HTML_LITERAL@21..31 "some text" [Newline("\n")] [],
},
HtmlElement {
opening_element: HtmlOpeningElement {
Expand Down Expand Up @@ -140,11 +137,9 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
3: [email protected]
0: [email protected] "some" [Newline("\n")] [Whitespace(" ")]
4: [email protected]
0: [email protected] "text" [] []
5: [email protected]
3: [email protected]
0: [email protected] "some text" [Newline("\n")] []
4: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n")] []
1: [email protected]
Expand All @@ -158,7 +153,7 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
6: [email protected]
5: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n")] []
1: [email protected]
Expand All @@ -172,7 +167,7 @@ HtmlRoot {
2: [email protected]
0: [email protected] "div" [] []
3: [email protected] ">" [] []
7: [email protected]
6: [email protected]
0: [email protected]
0: [email protected] "<" [Newline("\n")] []
1: [email protected]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>"<span>Foo</span>" is the title.</p>
117 changes: 117 additions & 0 deletions crates/biome_html_parser/tests/html_specs/ok/quote-in-child.html.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
source: crates/biome_html_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```html
<p>"<span>Foo</span>" is the title.</p>
```


## AST

```
HtmlRoot {
bom_token: missing (optional),
directive: missing (optional),
html: HtmlElementList [
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@0..1 "<" [] [],
name: HtmlName {
value_token: HTML_LITERAL@1..2 "p" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@2..3 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@3..4 "\"" [] [],
},
HtmlElement {
opening_element: HtmlOpeningElement {
l_angle_token: L_ANGLE@4..5 "<" [] [],
name: HtmlName {
value_token: HTML_LITERAL@5..9 "span" [] [],
},
attributes: HtmlAttributeList [],
r_angle_token: R_ANGLE@9..10 ">" [] [],
},
children: HtmlElementList [
HtmlContent {
value_token: HTML_LITERAL@10..13 "Foo" [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@13..14 "<" [] [],
slash_token: SLASH@14..15 "/" [] [],
name: HtmlName {
value_token: HTML_LITERAL@15..19 "span" [] [],
},
r_angle_token: R_ANGLE@19..20 ">" [] [],
},
},
HtmlContent {
value_token: HTML_LITERAL@20..35 "\" is the title." [] [],
},
],
closing_element: HtmlClosingElement {
l_angle_token: L_ANGLE@35..36 "<" [] [],
slash_token: SLASH@36..37 "/" [] [],
name: HtmlName {
value_token: HTML_LITERAL@37..38 "p" [] [],
},
r_angle_token: R_ANGLE@38..39 ">" [] [],
},
},
],
eof_token: EOF@39..40 "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: (empty)
2: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "<" [] []
1: [email protected]
0: [email protected] "p" [] []
2: [email protected]
3: [email protected] ">" [] []
1: [email protected]
0: [email protected]
0: [email protected] "\"" [] []
1: [email protected]
0: [email protected]
0: [email protected] "<" [] []
1: [email protected]
0: [email protected] "span" [] []
2: [email protected]
3: [email protected] ">" [] []
1: [email protected]
0: [email protected]
0: [email protected] "Foo" [] []
2: [email protected]
0: [email protected] "<" [] []
1: [email protected] "/" [] []
2: [email protected]
0: [email protected] "span" [] []
3: [email protected] ">" [] []
2: [email protected]
0: [email protected] "\" is the title." [] []
2: [email protected]
0: [email protected] "<" [] []
1: [email protected] "/" [] []
2: [email protected]
0: [email protected] "p" [] []
3: [email protected] ">" [] []
3: [email protected] "" [Newline("\n")] []
```

0 comments on commit b7a77c2

Please sign in to comment.