mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
6e03ed32c7
commit
f80d002438
3 changed files with 33 additions and 9 deletions
|
|
@ -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")},
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue