Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: panics on NaN map keys #43207

Open
dsnet opened this issue Dec 16, 2020 · 4 comments
Open

encoding/json: panics on NaN map keys #43207

dsnet opened this issue Dec 16, 2020 · 4 comments

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Dec 16, 2020

Using go1.16

Reproduction:

type F64 float64

func (f F64) MarshalText() ([]byte, error) {
	return []byte(fmt.Sprint(f)), nil
}

func main() {
	m := map[F64]string{F64(math.NaN()): "NaN"}
	json.Marshal(m)
}

Panics with panic: reflect: call of reflect.Value.Type on zero Value

@dsnet dsnet added the NeedsFix label Dec 16, 2020
@mvdan mvdan added the help wanted label Dec 16, 2020
@gopherbot
Copy link

@gopherbot gopherbot commented Dec 16, 2020

Change https://golang.org/cl/278632 mentions this issue: encoding/json: fix invalid kind reflect type

@bcmills
Copy link
Member

@bcmills bcmills commented Dec 16, 2020

See previously #14427, #24075, #20660. (NaN keys are trouble!)

@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 16, 2020

More precisely: NaN keys are trouble.

@mengzhuo
Copy link
Contributor

@mengzhuo mengzhuo commented Dec 17, 2020

More precisely: NaN keys are trouble.

Float as key is unsuppored, however this bug is about marhsal maps with interface MarshalText :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants