json: only use alphanumeric tags

Almost the same definition as Go identifier names.
(Leading digits are allowed.)

Fixes #1520.

R=r, r2
CC=golang-dev
https://golang.org/cl/4173061
This commit is contained in:
Russ Cox 2011-02-17 17:14:19 -05:00
parent 6e03ed32c7
commit f80d002438
3 changed files with 33 additions and 9 deletions

View file

@ -40,6 +40,11 @@ var (
umtrue = unmarshaler{true}
)
type badTag struct {
X string
Y string "y"
Z string "@#*%(#@"
}
type unmarshalTest struct {
in string
@ -62,6 +67,9 @@ var unmarshalTests = []unmarshalTest{
{`{"X": [1,2,3], "Y": 4}`, new(T), T{Y: 4}, &UnmarshalTypeError{"array", reflect.Typeof("")}},
{`{"x": 1}`, new(tx), tx{}, &UnmarshalFieldError{"x", txType, txType.Field(0)}},
// skip invalid tags
{`{"X":"a", "y":"b", "Z":"c"}`, new(badTag), badTag{"a", "b", "c"}, nil},
// syntax errors
{`{"X": "foo", "Y"}`, nil, nil, SyntaxError("invalid character '}' after object key")},