From 57ed39fd3bca9c69c32e55eb0a1873ab7f20bcfc Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Wed, 23 Nov 2011 09:26:37 +1100 Subject: [PATCH] html: on EOF in a comment, ignore final dashes (up to 2) Pass tests2.dat, test 57: | | | Also pass test 58:

R=nigeltao CC=golang-dev https://golang.org/cl/5436048 --- src/pkg/html/parse_test.go | 2 +- src/pkg/html/token.go | 6 +++++- src/pkg/html/token_test.go | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/pkg/html/parse_test.go b/src/pkg/html/parse_test.go index 3566f9f9417..c1347c9dc1c 100644 --- a/src/pkg/html/parse_test.go +++ b/src/pkg/html/parse_test.go @@ -134,7 +134,7 @@ func TestParser(t *testing.T) { }{ // TODO(nigeltao): Process all the test cases from all the .dat files. {"tests1.dat", -1}, - {"tests2.dat", 57}, + {"tests2.dat", 59}, {"tests3.dat", 0}, } for _, tf := range testFiles { diff --git a/src/pkg/html/token.go b/src/pkg/html/token.go index 9400873e6b8..a6fbcdfcfe5 100644 --- a/src/pkg/html/token.go +++ b/src/pkg/html/token.go @@ -289,7 +289,11 @@ func (z *Tokenizer) readComment() { for dashCount := 2; ; { c := z.readByte() if z.err != nil { - z.data.end = z.raw.end + // Ignore up to two dashes at EOF. + if dashCount > 2 { + dashCount = 2 + } + z.data.end = z.raw.end - dashCount return } switch c { diff --git a/src/pkg/html/token_test.go b/src/pkg/html/token_test.go index 61d4e67c06d..672d60c4209 100644 --- a/src/pkg/html/token_test.go +++ b/src/pkg/html/token_test.go @@ -325,6 +325,26 @@ var tokenTests = []tokenTest{ }, { "comment9", + "a", + }, + { + "comment10", + "a", + }, + { + "comment11", + "a", + }, + { + "comment12", + "a", + }, + { + "comment13", "az", "a$$z", },