Commit 57ed39fd authored by Andrew Balholm's avatar Andrew Balholm Committed by Nigel Tao

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
parent 79bce499
...@@ -134,7 +134,7 @@ func TestParser(t *testing.T) { ...@@ -134,7 +134,7 @@ func TestParser(t *testing.T) {
}{ }{
// TODO(nigeltao): Process all the test cases from all the .dat files. // TODO(nigeltao): Process all the test cases from all the .dat files.
{"tests1.dat", -1}, {"tests1.dat", -1},
{"tests2.dat", 57}, {"tests2.dat", 59},
{"tests3.dat", 0}, {"tests3.dat", 0},
} }
for _, tf := range testFiles { for _, tf := range testFiles {
......
...@@ -289,7 +289,11 @@ func (z *Tokenizer) readComment() { ...@@ -289,7 +289,11 @@ func (z *Tokenizer) readComment() {
for dashCount := 2; ; { for dashCount := 2; ; {
c := z.readByte() c := z.readByte()
if z.err != nil { 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 return
} }
switch c { switch c {
......
...@@ -325,6 +325,26 @@ var tokenTests = []tokenTest{ ...@@ -325,6 +325,26 @@ var tokenTests = []tokenTest{
}, },
{ {
"comment9", "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",
"a$<!--x-->$z", "a$<!--x-->$z",
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment