]> Cypherpunks repositories - gostls13.git/commitdiff
html: on EOF in a comment, ignore final dashes (up to 2)
authorAndrew Balholm <andybalholm@gmail.com>
Tue, 22 Nov 2011 22:26:37 +0000 (09:26 +1100)
committerNigel Tao <nigeltao@golang.org>
Tue, 22 Nov 2011 22:26:37 +0000 (09:26 +1100)
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

src/pkg/html/parse_test.go
src/pkg/html/token.go
src/pkg/html/token_test.go

index 3566f9f9417eaeb99e96e3bf94a60e767828553d..c1347c9dc1c0b861e2dea59f7334948219f6163c 100644 (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 {
index 9400873e6b8e6b81639d8358700f63910032bda6..a6fbcdfcfe52ef785779985e69171e51ce9d4635 100644 (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 {
index 61d4e67c06d7f178400672a65d539fda6e5d1b30..672d60c420940b558f85822013faa9b82d0e80ed 100644 (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",
        },