mirror of
https://github.com/golang/go
synced 2024-11-24 10:10:07 -07:00
encoding/gob: don't send type info for unexported fields
Fixes #2517. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/5440079
This commit is contained in:
parent
8bc6410837
commit
30775f67e7
@ -119,7 +119,9 @@ func (enc *Encoder) sendActualType(w io.Writer, state *encoderState, ut *userTyp
|
||||
switch st := actual; st.Kind() {
|
||||
case reflect.Struct:
|
||||
for i := 0; i < st.NumField(); i++ {
|
||||
enc.sendType(w, state, st.Field(i).Type)
|
||||
if isExported(st.Field(i).Name) {
|
||||
enc.sendType(w, state, st.Field(i).Type)
|
||||
}
|
||||
}
|
||||
case reflect.Array, reflect.Slice:
|
||||
enc.sendType(w, state, st.Elem())
|
||||
|
@ -662,3 +662,19 @@ func TestSequentialDecoder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Should be able to have unrepresentable fields (chan, func) as long as they
|
||||
// are unexported.
|
||||
type Bug2 struct {
|
||||
A int
|
||||
b chan int
|
||||
}
|
||||
|
||||
func TestUnexportedChan(t *testing.T) {
|
||||
b := Bug2{23, make(chan int)}
|
||||
var stream bytes.Buffer
|
||||
enc := NewEncoder(&stream)
|
||||
if err := enc.Encode(b); err != nil {
|
||||
t.Fatalf("error encoding unexported channel: %s", err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user