Skip to content

Commit bfdce0b

Browse files
authored
fix(parse/html): make . a valid char in tag names (#6693)
1 parent bdc167a commit bfdce0b

File tree

4 files changed

+118
-2
lines changed

4 files changed

+118
-2
lines changed

.changeset/lucky-adults-rhyme.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
The HTML parser will now consider `.` to be a valid character for tag names. Fixes [#6691](https://github.com/biomejs/biome/issues/6691).

crates/biome_html_parser/src/lexer/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,9 +700,10 @@ fn is_tag_name_byte(byte: u8) -> bool {
700700
// However, custom tag names must start with a lowercase letter, but they can be followed by pretty much anything else.
701701
// https://html.spec.whatwg.org/#valid-custom-element-name
702702

703-
// FIXME: The extra characters allowed here `-` and `:` is a temporary fix for now to fix parsing issues in some prettier test cases.
703+
// The extra characters allowed here `-`, `:`, and `.` are not usually allowed in the HTML tag name.
704+
// However, Prettier considers them to be valid characters in tag names, so we allow them to remain compatible.
704705

705-
byte.is_ascii_alphanumeric() || byte == b'-' || byte == b':'
706+
byte.is_ascii_alphanumeric() || byte == b'-' || byte == b':' || byte == b'.'
706707
}
707708

708709
fn is_attribute_name_byte(byte: u8) -> bool {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<f:link.external uri="https://domain.de/" class="underline hover:text-primary-text">Text</f:link.external>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
source: crates/biome_html_parser/tests/spec_test.rs
3+
expression: snapshot
4+
---
5+
## Input
6+
7+
```html
8+
<f:link.external uri="https://domain.de/" class="underline hover:text-primary-text">Text</f:link.external>
9+
```
10+
11+
12+
## AST
13+
14+
```
15+
HtmlRoot {
16+
bom_token: missing (optional),
17+
directive: missing (optional),
18+
html: HtmlElementList [
19+
HtmlElement {
20+
opening_element: HtmlOpeningElement {
21+
l_angle_token: L_ANGLE@0..1 "<" [] [],
22+
name: HtmlTagName {
23+
value_token: HTML_LITERAL@1..17 "f:link.external" [] [Whitespace(" ")],
24+
},
25+
attributes: HtmlAttributeList [
26+
HtmlAttribute {
27+
name: HtmlAttributeName {
28+
value_token: HTML_LITERAL@17..20 "uri" [] [],
29+
},
30+
initializer: HtmlAttributeInitializerClause {
31+
eq_token: EQ@20..21 "=" [] [],
32+
value: HtmlString {
33+
value_token: HTML_STRING_LITERAL@21..42 "\"https://domain.de/\"" [] [Whitespace(" ")],
34+
},
35+
},
36+
},
37+
HtmlAttribute {
38+
name: HtmlAttributeName {
39+
value_token: HTML_LITERAL@42..47 "class" [] [],
40+
},
41+
initializer: HtmlAttributeInitializerClause {
42+
eq_token: EQ@47..48 "=" [] [],
43+
value: HtmlString {
44+
value_token: HTML_STRING_LITERAL@48..83 "\"underline hover:text-primary-text\"" [] [],
45+
},
46+
},
47+
},
48+
],
49+
r_angle_token: R_ANGLE@83..84 ">" [] [],
50+
},
51+
children: HtmlElementList [
52+
HtmlContent {
53+
value_token: HTML_LITERAL@84..88 "Text" [] [],
54+
},
55+
],
56+
closing_element: HtmlClosingElement {
57+
l_angle_token: L_ANGLE@88..89 "<" [] [],
58+
slash_token: SLASH@89..90 "/" [] [],
59+
name: HtmlTagName {
60+
value_token: HTML_LITERAL@90..105 "f:link.external" [] [],
61+
},
62+
r_angle_token: R_ANGLE@105..106 ">" [] [],
63+
},
64+
},
65+
],
66+
eof_token: EOF@106..106 "" [] [],
67+
}
68+
```
69+
70+
## CST
71+
72+
```
73+
0: HTML_ROOT@0..106
74+
0: (empty)
75+
1: (empty)
76+
2: HTML_ELEMENT_LIST@0..106
77+
0: HTML_ELEMENT@0..106
78+
0: HTML_OPENING_ELEMENT@0..84
79+
0: L_ANGLE@0..1 "<" [] []
80+
1: HTML_TAG_NAME@1..17
81+
0: HTML_LITERAL@1..17 "f:link.external" [] [Whitespace(" ")]
82+
2: HTML_ATTRIBUTE_LIST@17..83
83+
0: HTML_ATTRIBUTE@17..42
84+
0: HTML_ATTRIBUTE_NAME@17..20
85+
0: HTML_LITERAL@17..20 "uri" [] []
86+
1: HTML_ATTRIBUTE_INITIALIZER_CLAUSE@20..42
87+
0: EQ@20..21 "=" [] []
88+
1: HTML_STRING@21..42
89+
0: HTML_STRING_LITERAL@21..42 "\"https://domain.de/\"" [] [Whitespace(" ")]
90+
1: HTML_ATTRIBUTE@42..83
91+
0: HTML_ATTRIBUTE_NAME@42..47
92+
0: HTML_LITERAL@42..47 "class" [] []
93+
1: HTML_ATTRIBUTE_INITIALIZER_CLAUSE@47..83
94+
0: EQ@47..48 "=" [] []
95+
1: HTML_STRING@48..83
96+
0: HTML_STRING_LITERAL@48..83 "\"underline hover:text-primary-text\"" [] []
97+
3: R_ANGLE@83..84 ">" [] []
98+
1: HTML_ELEMENT_LIST@84..88
99+
0: HTML_CONTENT@84..88
100+
0: HTML_LITERAL@84..88 "Text" [] []
101+
2: HTML_CLOSING_ELEMENT@88..106
102+
0: L_ANGLE@88..89 "<" [] []
103+
1: SLASH@89..90 "/" [] []
104+
2: HTML_TAG_NAME@90..105
105+
0: HTML_LITERAL@90..105 "f:link.external" [] []
106+
3: R_ANGLE@105..106 ">" [] []
107+
3: EOF@106..106 "" [] []
108+
109+
```

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy