diff options
| author | Russ Cox <rsc@golang.org> | 2013-03-12 00:29:36 -0400 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2013-03-12 00:29:36 -0400 |
| commit | 019754ed4036f9ddc7514c78548fe77a606464db (patch) | |
| tree | b08e4766ba6b8a91614f54159c68dfb660294439 /src/pkg/encoding | |
| parent | aa81eb5901abc545bc8ff14833f52c3e798f0b90 (diff) | |
| download | go-019754ed4036f9ddc7514c78548fe77a606464db.tar.xz | |
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
Diffstat (limited to 'src/pkg/encoding')
| -rw-r--r-- | src/pkg/encoding/xml/xml.go | 2 | ||||
| -rw-r--r-- | 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<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) } } } |
