Skip to content

Commit

Permalink
feat: improve parsing of DOCTYPE to handle mistakes in tag closing
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h committed Jun 25, 2021
1 parent 5605e7f commit c926663
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doctypeparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ func (p docTypeParser) Parse(pi parse.Input) parse.Result {
}

// Once a doctype has started, take everything until the end.
tagOpen := parse.Rune('<')
tagClose := parse.Rune('>')
dtr = parse.StringUntil(tagClose)(pi)
dtr = parse.StringUntil(parse.Or(tagClose, tagOpen))(pi)
if dtr.Error != nil && dtr.Error != io.EOF {
return dtr
}
Expand Down
20 changes: 18 additions & 2 deletions doctypeparser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,25 @@ func TestDocTypeParserErrors(t *testing.T) {
Col: 0,
},
Position{
Index: 16,
Index: 17,
Line: 1,
Col: 16,
Col: 17,
}),
},
{
name: "doctype new tag started",
input: `<!DOCTYPE html
<div>`,
expected: newParseError("unclosed DOCTYPE",
Position{
Index: 17,
Line: 2,
Col: 2,
},
Position{
Index: 17,
Line: 2,
Col: 2,
}),
},
}
Expand Down

0 comments on commit c926663

Please sign in to comment.