From 019754ed4036f9ddc7514c78548fe77a606464db Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 12 Mar 2013 00:29:36 -0400 Subject: [PATCH] encoding/xml: fix spurious "no semicolon" in error Noticed while doing other XML investigations. R=golang-dev, r CC=golang-dev https://golang.org/cl/7550045 --- src/pkg/encoding/xml/xml.go | 2 +- src/pkg/encoding/xml/xml_test.go | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/pkg/encoding/xml/xml.go b/src/pkg/encoding/xml/xml.go index 143fec554c..1f900b623c 100644 --- a/src/pkg/encoding/xml/xml.go +++ b/src/pkg/encoding/xml/xml.go @@ -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)" } diff --git a/src/pkg/encoding/xml/xml_test.go b/src/pkg/encoding/xml/xml_test.go index 54dab5484a..5a4e214710 100644 --- a/src/pkg/encoding/xml/xml_test.go +++ b/src/pkg/encoding/xml/xml_test.go @@ -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", "illegal character code U+FFFE"}, {"\r\n\x07", "illegal character code U+0007"}, {"what's up", "expected attribute name in element"}, + {"&abc\x01;", "invalid character entity &abc (no semicolon)"}, {"&\x01;", "invalid character entity & (no semicolon)"}, - {"&\xef\xbf\xbe;", "invalid character entity & (no semicolon)"}, + {"&\xef\xbf\xbe;", "invalid character entity &\uFFFE;"}, + {"&hello;", "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) } } }