Skip to content

Commit 5ca2af9

Browse files
committed
Fix: bugs about end-tag-with-attributes
1 parent ed1e40b commit 5ca2af9

File tree

5 files changed

+1036
-78
lines changed

5 files changed

+1036
-78
lines changed

src/html/parser.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as lodash from "lodash"
77
import {debug} from "../common/debug"
88
import {ErrorCode, Namespace, NS, ParseError, Token, VAttribute, VDocumentFragment, VElement, VNode, VText} from "../ast"
99
import {MATHML_ATTRIBUTE_NAME_MAP, SVG_ATTRIBUTE_NAME_MAP} from "./util/attribute-names"
10-
import {HTML_CAN_BE_LEFT_OPEN_TAGS, HTML_NON_FHRASING_TAGS, HTML_VOID_ELEMENT_TAGS, SVG_ELEMENT_NAME_MAP} from "./util/tag-names"
10+
import {HTML_CAN_BE_LEFT_OPEN_TAGS, HTML_NON_FHRASING_TAGS, HTML_RAWTEXT_TAGS, HTML_RCDATA_TAGS, HTML_VOID_ELEMENT_TAGS, SVG_ELEMENT_NAME_MAP} from "./util/tag-names"
1111
import {Tokenizer, TokenType} from "./tokenizer"
1212

1313
/**
@@ -476,6 +476,9 @@ export class Parser {
476476
this.tokens.push(token)
477477

478478
const attribute = this.currentNode
479+
if (attribute.type === "VEndTag") {
480+
return
481+
}
479482
if (attribute.type !== "VAttribute" || attribute.directive === true) {
480483
throw new Error("unreachable")
481484
}
@@ -574,6 +577,16 @@ export class Parser {
574577
if (tag.type === "VEndTag" || HTML_VOID_ELEMENT_TAGS.has(tag.parent.name)) {
575578
this.popNodeStack()
576579
}
580+
581+
// Update the content type of this element.
582+
if (tag.type === "VStartTag" && tag.parent.namespace === NS.HTML) {
583+
if (HTML_RCDATA_TAGS.has(tag.parent.name)) {
584+
this.tokenizer.state = "RCDATA"
585+
}
586+
if (HTML_RAWTEXT_TAGS.has(tag.parent.name)) {
587+
this.tokenizer.state = "RAWTEXT"
588+
}
589+
}
577590
}
578591

579592
/**

0 commit comments

Comments
 (0)