Skip to content

Commit c8b1e38

Browse files
committed
Fix: bugs about non-void-html-element-start-tag-with-trailing-solidus
1 parent 569e8d8 commit c8b1e38

File tree

7 files changed

+24
-36
lines changed

7 files changed

+24
-36
lines changed

src/html/intermediate-tokenizer.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import assert from "assert"
77
import {ErrorCode, HasLocation, Namespace, ParseError, Token, VAttribute} from "../ast"
88
import {debug} from "../common/debug"
9-
import {HTML_VOID_ELEMENT_TAGS} from "./util/tag-names"
109
import {Tokenizer, TokenizerState, TokenType} from "./tokenizer"
1110

1211
const DUMMY_PARENT: any = Object.freeze({})
@@ -343,9 +342,6 @@ export class IntermediateTokenizer {
343342

344343
if (this.currentToken.type === "StartTag") {
345344
this.currentToken.selfClosing = true
346-
if (!HTML_VOID_ELEMENT_TAGS.has(this.currentToken.name)) {
347-
this.reportParseError(token, "non-void-html-element-start-tag-with-trailing-solidus")
348-
}
349345
}
350346
else {
351347
this.reportParseError(token, "end-tag-with-trailing-solidus")

src/html/parser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,14 @@ export class Parser {
324324
element.startTag.parent = element
325325
parent.children.push(element)
326326

327+
// Check whether the self-closing is valid.
328+
const isVoid = (namespace === NS.HTML && HTML_VOID_ELEMENT_TAGS.has(element.name))
329+
if (token.selfClosing && !isVoid && namespace === NS.HTML) {
330+
this.reportParseError(token, "non-void-html-element-start-tag-with-trailing-solidus")
331+
}
332+
327333
// Vue.js supports self-closing elements even if it's not one of void elements.
328-
if (token.selfClosing || HTML_VOID_ELEMENT_TAGS.has(element.name)) {
334+
if (token.selfClosing || isVoid) {
329335
return
330336
}
331337

test/fixtures/ast/cdata/ast.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,13 +1153,6 @@
11531153
}
11541154
],
11551155
"comments": [],
1156-
"errors": [
1157-
{
1158-
"message": "non-void-html-element-start-tag-with-trailing-solidus (9:31)",
1159-
"index": 235,
1160-
"lineNumber": 9,
1161-
"column": 31
1162-
}
1163-
]
1156+
"errors": []
11641157
}
11651158
}

test/fixtures/ast/error-unexpected-solidus-in-tag/ast.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,10 @@
418418
"column": 12
419419
},
420420
{
421-
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:15)",
422-
"index": 26,
421+
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:4)",
422+
"index": 15,
423423
"lineNumber": 2,
424-
"column": 15
424+
"column": 4
425425
}
426426
]
427427
}

test/fixtures/ast/math/ast.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7091,13 +7091,6 @@
70917091
}
70927092
],
70937093
"comments": [],
7094-
"errors": [
7095-
{
7096-
"message": "non-void-html-element-start-tag-with-trailing-solidus (44:27)",
7097-
"index": 1433,
7098-
"lineNumber": 44,
7099-
"column": 27
7100-
}
7101-
]
7094+
"errors": []
71027095
}
71037096
}

test/fixtures/ast/self-closing-elements/ast.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -543,22 +543,22 @@
543543
"comments": [],
544544
"errors": [
545545
{
546-
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:9)",
547-
"index": 20,
546+
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:4)",
547+
"index": 15,
548548
"lineNumber": 2,
549-
"column": 9
549+
"column": 4
550550
},
551551
{
552-
"message": "non-void-html-element-start-tag-with-trailing-solidus (3:9)",
553-
"index": 32,
552+
"message": "non-void-html-element-start-tag-with-trailing-solidus (3:4)",
553+
"index": 27,
554554
"lineNumber": 3,
555-
"column": 9
555+
"column": 4
556556
},
557557
{
558-
"message": "non-void-html-element-start-tag-with-trailing-solidus (4:9)",
559-
"index": 44,
558+
"message": "non-void-html-element-start-tag-with-trailing-solidus (4:4)",
559+
"index": 39,
560560
"lineNumber": 4,
561-
"column": 9
561+
"column": 4
562562
}
563563
]
564564
}

test/fixtures/ast/textarea/ast.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,10 +1380,10 @@
13801380
"comments": [],
13811381
"errors": [
13821382
{
1383-
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:13)",
1384-
"index": 24,
1383+
"message": "non-void-html-element-start-tag-with-trailing-solidus (2:4)",
1384+
"index": 15,
13851385
"lineNumber": 2,
1386-
"column": 13
1386+
"column": 4
13871387
}
13881388
]
13891389
}

0 commit comments

Comments
 (0)