encoding/json: Unmarshalling *websocket.Conn over a websocket with JSON crashes #14665
Labels
Comments
I have no strong opinion on how unexposed, non-assignable fields should be treated in encoding/json package. |
the json package maybe should just check if a field is exported or not for the internal type cache? |
I am unable to reproduce this. Do you have a repro? I tried: package main
import (
"encoding/json"
"fmt"
"log"
"golang.org/x/net/websocket"
)
func main() {
type T struct {
Foo string
conn *websocket.Conn
}
t := &T{"bar", new(websocket.Conn)}
enc, err := json.Marshal(t)
if err != nil {
log.Fatalf("Marshal: %v", err)
}
var t2 T
if err := json.Unmarshal(enc, &t2); err != nil {
log.Fatalf("Unmarshal: %v", err)
}
fmt.Printf("%#v\n", t2)
} But it works at tip, Go 1.6, and Go 1.5 just fine with:
Let me know and I can reopen this. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
go version
)?go version go1.6 linux/amd64
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dolanor/.local/gopath/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
I sent a *websocket.Conn on a websocket in JSON (by pure laziness, without caring about having it on the other side).
I expected to get unmarshalling kind of working, even if the *websocket.Conn wouldn't work: I didn't really wanted to get this information on the other side, but it was part of a struct I wanted to send over the wire.
If I put this *websocket.Conn to nil, then I don't get problems on the other side.
The text was updated successfully, but these errors were encountered: