Skip to content

Commit

Permalink
HTML: revert changes to start tag parsing, see #123
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Oct 15, 2024
1 parent 5767286 commit 16b18e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion html/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ func (l *Lexer) shiftBogusComment() []byte {

func (l *Lexer) shiftStartTag() (TokenType, []byte) {
for {
if c := l.r.Peek(0); !('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || '0' <= c && c <= '9' || c == '-') {
// spec says only a-zA-Z0-9, but we're lenient here
if c := l.r.Peek(0); c == ' ' || c == '>' || c == '/' && l.r.Peek(1) == '>' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == 0 && l.r.Err() != nil || 0 < len(l.tmplBegin) && l.at(l.tmplBegin...) {
break
}
l.r.Move(1)
Expand Down
7 changes: 4 additions & 3 deletions html/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestTokens(t *testing.T) {
// NULL
{"foo\x00bar", TTs{TextToken}},
{"<\x00foo>", TTs{TextToken}},
{"<foo\x00>", TTs{StartTagToken, AttributeToken, StartTagCloseToken}},
{"<foo\x00>", TTs{StartTagToken, StartTagCloseToken}},
{"</\x00bogus>", TTs{CommentToken}},
{"</foo\x00>", TTs{EndTagToken}},
{"<plaintext>\x00</plaintext>", TTs{StartTagToken, StartTagCloseToken, TextToken}},
Expand Down Expand Up @@ -110,8 +110,8 @@ func TestTags(t *testing.T) {
html string
expected string
}{
//{"<foo:bar.qux-norf/>", "foo:bar.qux-norf"},
//{"<foo?bar/qux>", "foo?bar/qux"},
{"<foo:bar.qux-norf/>", "foo:bar.qux-norf"}, // invalid but added for leniency with XHTML
{"<foo?bar/qux>", "foo?bar/qux"}, // invalid but added for leniency with XHTML
{"<!DOCTYPE note SYSTEM \"Note.dtd\">", " note SYSTEM \"Note.dtd\""},
{"</foo >", "foo"},

Expand Down Expand Up @@ -193,6 +193,7 @@ func TestTemplates(t *testing.T) {
{"<input {{if eq .Type 0}} selected {{end}}>", []bool{true, false, true}},
{"{{", []bool{true}},
{"{{'", []bool{true}},
{"<tag{{.Attr}}>", []bool{true}},
}
for _, tt := range tests {
t.Run(tt.html, func(t *testing.T) {
Expand Down

0 comments on commit 16b18e2

Please sign in to comment.