mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/xml: EncodeToken silently eats tokens with invalid type
EncodeToken takes a Token (i.e. an interface{}) as a parameter,
and expects a value of type StartElement, EndElement, CharData,
Comment, ProcInst, or Directive.
If a pointer is passed instead, or any type which does not match
this list, the token is silently ignored.
Added a default case in the type switch to issue a proper error
when the type is invalid.
The behavior could be later improved by allowing pointers to
token to be accepted as well, but not for go1.5.
Fixes #11719
Change-Id: Ifd13c1563450b474acf66d57669fdccba76c1949
Reviewed-on: https://go-review.googlesource.com/12252
Reviewed-by: Andrew Gerrand <adg@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
parent
74ec5bf2d8
commit
ca1d6c4b44
2 changed files with 35 additions and 0 deletions
|
|
@ -199,6 +199,7 @@ var (
|
|||
// elements (including the StartElement itself) will use the declared
|
||||
// prefix when encoding names with matching namespace URIs.
|
||||
func (enc *Encoder) EncodeToken(t Token) error {
|
||||
|
||||
p := &enc.p
|
||||
switch t := t.(type) {
|
||||
case StartElement:
|
||||
|
|
@ -245,6 +246,9 @@ func (enc *Encoder) EncodeToken(t Token) error {
|
|||
p.WriteString("<!")
|
||||
p.Write(t)
|
||||
p.WriteString(">")
|
||||
default:
|
||||
return fmt.Errorf("xml: EncodeToken of invalid token type")
|
||||
|
||||
}
|
||||
return p.cachedWriteError()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue