]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: fix spurious "no semicolon" in error
authorRuss Cox <rsc@golang.org>
Tue, 12 Mar 2013 04:29:36 +0000 (00:29 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 12 Mar 2013 04:29:36 +0000 (00:29 -0400)
Noticed while doing other XML investigations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7550045

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

index 143fec554cffbba72a3e7711662a6928374a477e..1f900b623cb6c1a5a5c866c7d213eddb8be7d91c 100644 (file)
@@ -956,7 +956,7 @@ Input:
                                b0, b1 = 0, 0
                                continue Input
                        }
-                       ent := string(d.buf.Bytes()[before])
+                       ent := string(d.buf.Bytes()[before:])
                        if ent[len(ent)-1] != ';' {
                                ent += " (no semicolon)"
                        }
index 54dab5484a6bdbdcc0c3b73c5217059c5f929f07..5a4e2147101a4e7987667be077405021b01e330f 100644 (file)
@@ -595,13 +595,6 @@ func TestEntityInsideCDATA(t *testing.T) {
        }
 }
 
-// The last three tests (respectively one for characters in attribute
-// names and two for character entities) pass not because of code
-// changed for issue 1259, but instead pass with the given messages
-// from other parts of xml.Decoder.  I provide these to note the
-// current behavior of situations where one might think that character
-// range checking would detect the error, but it does not in fact.
-
 var characterTests = []struct {
        in  string
        err string
@@ -611,8 +604,10 @@ var characterTests = []struct {
        {"\xef\xbf\xbe<doc/>", "illegal character code U+FFFE"},
        {"<?xml version=\"1.0\"?><doc>\r\n<hiya/>\x07<toots/></doc>", "illegal character code U+0007"},
        {"<?xml version=\"1.0\"?><doc \x12='value'>what's up</doc>", "expected attribute name in element"},
+       {"<doc>&abc\x01;</doc>", "invalid character entity &abc (no semicolon)"},
        {"<doc>&\x01;</doc>", "invalid character entity & (no semicolon)"},
-       {"<doc>&\xef\xbf\xbe;</doc>", "invalid character entity & (no semicolon)"},
+       {"<doc>&\xef\xbf\xbe;</doc>", "invalid character entity &\uFFFE;"},
+       {"<doc>&hello;</doc>", "invalid character entity &hello;"},
 }
 
 func TestDisallowedCharacters(t *testing.T) {
@@ -629,7 +624,7 @@ func TestDisallowedCharacters(t *testing.T) {
                        t.Fatalf("input %d d.Token() = _, %v, want _, *SyntaxError", i, err)
                }
                if synerr.Msg != tt.err {
-                       t.Fatalf("input %d synerr.Msg wrong: want '%s', got '%s'", i, tt.err, synerr.Msg)
+                       t.Fatalf("input %d synerr.Msg wrong: want %q, got %q", i, tt.err, synerr.Msg)
                }
        }
 }