]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/xml: don't panic when custom Unmarshaler sees StartElement
authorSam Whited <sam@samwhited.com>
Sat, 14 Oct 2017 03:28:57 +0000 (22:28 -0500)
committerIan Lance Taylor <iant@golang.org>
Mon, 30 Oct 2017 18:52:19 +0000 (18:52 +0000)
Change-Id: I90aa0a983abd0080f3de75d3340fdb15c1f9ca35
Reviewed-on: https://go-review.googlesource.com/70891
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Sam Whited <sam@samwhited.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/vet/all/whitelist/all.txt
src/encoding/xml/xml.go
src/encoding/xml/xml_test.go

index c28035f8bb9ceed874c8168ddbafb00e599acf6b..5467db98806c094b607168a3926b3a41d5bc703d 100644 (file)
@@ -48,6 +48,7 @@ encoding/xml/marshal.go: method MarshalXML(e *Encoder, start StartElement) error
 encoding/xml/marshal_test.go: method MarshalXML(e *Encoder, start StartElement) error should have signature MarshalXML(*xml.Encoder, xml.StartElement) error
 encoding/xml/read.go: method UnmarshalXML(d *Decoder, start StartElement) error should have signature UnmarshalXML(*xml.Decoder, xml.StartElement) error
 encoding/xml/read_test.go: method UnmarshalXML(d *Decoder, start StartElement) error should have signature UnmarshalXML(*xml.Decoder, xml.StartElement) error
+encoding/xml/xml_test.go: method UnmarshalXML(*Decoder, StartElement) error should have signature UnmarshalXML(*xml.Decoder, xml.StartElement) error
 
 // Long struct tags used to test reflect internals
 cmd/link/link_test.go: struct field tag "\n\tLondon. Michaelmas term lately over, and the Lord Chancellor sitting in Lincoln’s Inn Hall. Implacable November weather. As much mud in the streets as if the waters had but newly retired from the face of the earth, and it would not be wonderful to meet a Megalosaurus, forty feet long or so, waddling like an elephantine lizard up Holborn Hill. Smoke lowering down from chimney-pots, making a soft black drizzle, with flakes of soot in it as big as full-grown snowflakes—gone into mourning, one might imagine, for the death of the sun. Dogs, undistinguishable in mire. Horses, scarcely better; splashed to their very blinkers. Foot passengers, jostling one another’s umbrellas in a general infection of ill temper, and losing their foot-hold at street-corners, where tens of thousands of other foot passengers have been slipping and sliding since the day broke (if this day ever broke), adding new deposits to the crust upon crust of mud, sticking at those points tenaciously to the pavement, and accumulating at compound interest.\n\n\tFog everywhere. Fog up the river, where it flows among green aits and meadows; fog down the river, where it rolls defiled among the tiers of shipping and the waterside pollutions of a great (and dirty) city. Fog on the Essex marshes, fog on the Kentish heights. Fog creeping into the cabooses of collier-brigs; fog lying out on the yards and hovering in the rigging of great ships; fog drooping on the gunwales of barges and small boats. Fog in the eyes and throats of ancient Greenwich pensioners, wheezing by the firesides of their wards; fog in the stem and bowl of the afternoon pipe of the wrathful skipper, down in his close cabin; fog cruelly pinching the toes and fingers of his shivering little ‘prentice boy on deck. Chance people on the bridges peeping over the parapets into a nether sky of fog, with fog all round them, as if they were up in a balloon and hanging in the misty clouds.\n\n\tGas looming through the fog in divers places in the streets, much as the sun may, from the spongey fields, be seen to loom by husbandman and ploughboy. Most of the shops lighted two hours before their time—as the gas seems to know, for it has a haggard and unwilling look.\n\n\tThe raw afternoon is rawest, and the dense fog is densest, and the muddy streets are muddiest near that leaden-headed old obstruction, appropriate ornament for the threshold of a leaden-headed old corporation, Temple Bar. And hard by Temple Bar, in Lincoln’s Inn Hall, at the very heart of the fog, sits the Lord High Chancellor in his High Court of Chancery." not compatible with reflect.StructTag.Get: bad syntax for struct tag key
index be90b62c9a0fc7ff33b77ff72d2d1822093437b8..7556d4b8768909a92598c8f6b1df0f88be85cb88 100644 (file)
@@ -277,9 +277,6 @@ func NewTokenDecoder(t TokenReader) *Decoder {
 // If Token encounters an unrecognized name space prefix,
 // it uses the prefix as the Space rather than report an error.
 func (d *Decoder) Token() (Token, error) {
-       if d.t != nil {
-               return d.t.Token()
-       }
        var t Token
        var err error
        if d.stk != nil && d.stk.kind == stkEOF {
@@ -548,6 +545,9 @@ func (d *Decoder) RawToken() (Token, error) {
 }
 
 func (d *Decoder) rawToken() (Token, error) {
+       if d.t != nil {
+               return d.t.Token()
+       }
        if d.err != nil {
                return nil, d.err
        }
index 2437f19d9d16106cef45eba49909c2e06fc8eff8..7a3511d58328376d26e26a2cf13422f2ac6fd789 100644 (file)
@@ -861,3 +861,26 @@ func TestWrapDecoder(t *testing.T) {
                t.Fatalf("Got unexpected chardata: `%s`\n", o.Chardata)
        }
 }
+
+type tokReader struct{}
+
+func (tokReader) Token() (Token, error) {
+       return StartElement{}, nil
+}
+
+type Failure struct{}
+
+func (Failure) UnmarshalXML(*Decoder, StartElement) error {
+       return nil
+}
+
+func TestTokenUnmarshaler(t *testing.T) {
+       defer func() {
+               if r := recover(); r != nil {
+                       t.Error("Unexpected panic using custom token unmarshaler")
+               }
+       }()
+
+       d := NewTokenDecoder(tokReader{})
+       d.Decode(&Failure{})
+}