Fix stack overflow when whitespace appears after attribute name and before tag-closing >

This commit is contained in:
Shadowfacts 2024-02-06 18:46:56 -05:00
parent 7e624c0a4a
commit aed61d84d3
2 changed files with 9 additions and 2 deletions

View File

@ -731,7 +731,7 @@ private extension Tokenizer {
switch c {
case "\t", "\n", "\u{000C}", " ":
// ignore the character
return next()
return tokenizeBeforeAttributeName()
case "/", ">", nil:
reconsume(c)
state = .afterAttributeName
@ -794,13 +794,16 @@ private extension Tokenizer {
switch nextChar() {
case "\t", "\n", "\u{000C}", " ":
// ignore the character
return tokenizeAttributeName()
return tokenizeAfterAttributeName()
case "/":
state = .selfClosingStartTag
return tokenizeSelfClosingStartTag()
case "=":
state = .beforeAttributeValue
return tokenizeBeforeAttributeValue()
case ">":
state = .data
return takeCurrentToken()
case nil:
// parse error: eof-in-tag
state = .endOfFile

View File

@ -74,6 +74,10 @@ final class TokenizerTests: XCTestCase {
XCTAssertEqual(tokenize("🇺🇸"), [.characterSequence("\u{1F1FA}\u{1F1F8}")])
}
func testWhitespaceAfterAttributeName() {
XCTAssertEqual(tokenize("<a foo >"), [.startTag("a", selfClosing: false, attributes: [.init(name: "foo", value: "")])])
}
}
private struct PrintIterator<Inner: IteratorProtocol>: IteratorProtocol {