8000 Reject unsupported XML basic types by dajiaohuang · Pull Request #1791 · dominikh/go-tools · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion staticcheck/fakexml/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,19 @@ func (e *Encoder) marshalAttr(start *StartElement, name Name, val fakereflect.Ty

func (e *Encoder) marshalSimple(val fakereflect.TypeAndCanAddr, stack string) error {
switch val.Type.Underlying().(type) {
case *types.Basic, *types.Interface:
case *types.Basic:
basic := val.Type.Underlying().(*types.Basic)
switch basic.Kind() {
case types.Bool,
types.Int, types.Int8, types.Int16, types.Int32, types.Int64,
types.Uint, types.Uint8, types.Uint16, types.Uint32, types.Uint64, types.Uintptr,
types.Float32, types.Float64, types.String,
types.UntypedBool, types.UntypedInt, types.UntypedRune, types.UntypedFloat, types.UntypedString, types.UntypedNil:
return nil
default:
return &UnsupportedTypeError{val.Type, stack}
}
case *types.Interface:
return nil
case *types.Slice, *types.Array:
basic, ok := val.Elem().Type.Underlying().(*types.Basic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"encoding/xml"
"time"
"unsafe"
)

type T1 struct {
Expand Down Expand Up @@ -281,6 +282,13 @@ func otherPackageXML() {
xml.Marshal(x) //@ diag(`unsupported type <-chan time.Time, via x.C`)
}

func unsupportedXMLBasicTypes() {
var c complex128
var p unsafe.Pointer
xml.Marshal(c) //@ diag(`unsupported type complex128`)
xml.Marshal(p) //@ diag(`unsupported type unsafe.Pointer`)
}

type ToplevelPointerMarshalerXML struct {
Field map[string]string
}
Expand Down
0