]> Cypherpunks repositories - gostls13.git/commitdiff
xml: Allow entities inside CDATA tags
authorDan Sinclair <dan.sinclair@gmail.com>
Fri, 24 Sep 2010 16:23:01 +0000 (12:23 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 24 Sep 2010 16:23:01 +0000 (12:23 -0400)
Fixes #1112.

R=rsc
CC=golang-dev
https://golang.org/cl/2255042

src/pkg/xml/xml.go
src/pkg/xml/xml_test.go

index cd67f6e2657fc9faf5c2960c12f91e0bcded5b10..29fc739497f6b5879546a5934f1c0bca9ce5f416 100644 (file)
@@ -790,7 +790,7 @@ Input:
                if quote >= 0 && b == byte(quote) {
                        break Input
                }
-               if b == '&' {
+               if b == '&' && !cdata {
                        // Read escaped character expression up to semicolon.
                        // XML in all its glory allows a document to define and use
                        // its own character names with <!ENTITY ...> directives.
index 148bd2cd0c5657224802ab777d48eab9970e0609..c1688088e6cda40c34663ffd2c1a180b7bbc43b7 100644 (file)
@@ -387,3 +387,14 @@ func TestTrailingToken(t *testing.T) {
                t.Fatalf("p.Token() = _, %v, want _, os.EOF", err)
        }
 }
+
+func TestEntityInsideCDATA(t *testing.T) {
+       input := `<test><![CDATA[ &val=foo ]]></test>`
+       p := NewParser(StringReader(input))
+       var err os.Error
+       for _, err = p.Token(); err == nil; _, err = p.Token() {
+       }
+       if err != os.EOF {
+               t.Fatalf("p.Token() = _, %v, want _, os.EOF", err)
+       }
+}