1
0
mirror of https://github.com/golang/go synced 2024-11-20 08:04:42 -07:00

html: on EOF in a comment, ignore final dashes (up to 2)

Pass tests2.dat, test 57:
<!DOCTYPE html><!--x--

| <!DOCTYPE html>
| <!-- x -->
| <html>
|   <head>
|   <body>

Also pass test 58:
<!DOCTYPE html><table><tr><td></p></table>

R=nigeltao
CC=golang-dev
https://golang.org/cl/5436048
This commit is contained in:
Andrew Balholm 2011-11-23 09:26:37 +11:00 committed by Nigel Tao
parent 79bce499a3
commit 57ed39fd3b
3 changed files with 26 additions and 2 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -325,6 +325,26 @@ var tokenTests = []tokenTest{
},
{
"comment9",
"a<!--z-",
"a$<!--z-->",
},
{
"comment10",
"a<!--z--",
"a$<!--z-->",
},
{
"comment11",
"a<!--z---",
"a$<!--z--->",
},
{
"comment12",
"a<!--z----",
"a$<!--z---->",
},
{
"comment13",
"a<!--x--!>z",
"a$<!--x-->$z",
},