Skip to content

Commit

Permalink
fix(parser): should not treat uppercase components as special tags
Browse files Browse the repository at this point in the history
close #10338
  • Loading branch information
yyx990803 committed Feb 25, 2024
1 parent 9a365fe commit 904ef80
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 6 additions & 9 deletions packages/compiler-core/src/tokenizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,12 +553,11 @@ export default class Tokenizer {
// HTML mode
// - <script>, <style> RAWTEXT
// - <title>, <textarea> RCDATA
const lower = c | 0x20
if (lower === 116 /* t */) {
if (c === 116 /* t */) {
this.state = State.BeforeSpecialT
} else {
this.state =
lower === 115 /* s */ ? State.BeforeSpecialS : State.InTagName
c === 115 /* s */ ? State.BeforeSpecialS : State.InTagName
}
} else {
this.state = State.InTagName
Expand Down Expand Up @@ -862,21 +861,19 @@ export default class Tokenizer {
}
}
private stateBeforeSpecialS(c: number): void {
const lower = c | 0x20
if (lower === Sequences.ScriptEnd[3]) {
if (c === Sequences.ScriptEnd[3]) {
this.startSpecial(Sequences.ScriptEnd, 4)
} else if (lower === Sequences.StyleEnd[3]) {
} else if (c === Sequences.StyleEnd[3]) {
this.startSpecial(Sequences.StyleEnd, 4)
} else {
this.state = State.InTagName
this.stateInTagName(c) // Consume the token again
}
}
private stateBeforeSpecialT(c: number): void {
const lower = c | 0x20
if (lower === Sequences.TitleEnd[3]) {
if (c === Sequences.TitleEnd[3]) {
this.startSpecial(Sequences.TitleEnd, 4)
} else if (lower === Sequences.TextareaEnd[3]) {
} else if (c === Sequences.TextareaEnd[3]) {
this.startSpecial(Sequences.TextareaEnd, 4)
} else {
this.state = State.InTagName
Expand Down
16 changes: 15 additions & 1 deletion packages/compiler-dom/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('DOM parser', () => {
)
const element = ast.children[0] as ElementNode
const text = element.children[0] as TextNode

expect(element.children.length).toBe(1)
expect(text).toStrictEqual({
type: NodeTypes.TEXT,
content: 'some<div>text</div>and<!--comment-->',
Expand All @@ -32,6 +32,20 @@ describe('DOM parser', () => {
})
})

test('should not treat Uppercase component as special tag', () => {
const ast = parse(
'<TextArea>some<div>text</div>and<!--comment--></TextArea>',
parserOptions,
)
const element = ast.children[0] as ElementNode
expect(element.children.map(n => n.type)).toMatchObject([
NodeTypes.TEXT,
NodeTypes.ELEMENT,
NodeTypes.TEXT,
NodeTypes.COMMENT,
])
})

test('textarea handles entities', () => {
const ast = parse('<textarea>&amp;</textarea>', parserOptions)
const element = ast.children[0] as ElementNode
Expand Down

0 comments on commit 904ef80

Please sign in to comment.