mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
json: object members must have a value
R=rsc CC=golang-dev https://golang.org/cl/1847050
This commit is contained in:
parent
3ab7830d7d
commit
2db4c3d779
2 changed files with 11 additions and 5 deletions
|
|
@ -37,6 +37,9 @@ var unmarshalTests = []unmarshalTest{
|
|||
unmarshalTest{"null", new(interface{}), nil, nil},
|
||||
unmarshalTest{`{"X": [1,2,3], "Y": 4}`, new(T), T{Y: 4}, &UnmarshalTypeError{"array", reflect.Typeof("")}},
|
||||
|
||||
// syntax errors
|
||||
unmarshalTest{`{"X": "foo", "Y"}`, nil, nil, SyntaxError("invalid character '}' after object key")},
|
||||
|
||||
// composite tests
|
||||
unmarshalTest{allValueIndent, new(All), allValue, nil},
|
||||
unmarshalTest{allValueCompact, new(All), allValue, nil},
|
||||
|
|
@ -75,9 +78,14 @@ func TestUnmarshal(t *testing.T) {
|
|||
for i, tt := range unmarshalTests {
|
||||
in := []byte(tt.in)
|
||||
if err := checkValid(in, &scan); err != nil {
|
||||
if !reflect.DeepEqual(err, tt.err) {
|
||||
t.Errorf("#%d: checkValid: %v", i, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if tt.ptr == nil {
|
||||
continue
|
||||
}
|
||||
// v = new(right-type)
|
||||
v := reflect.NewValue(tt.ptr).(*reflect.PtrValue)
|
||||
v.PointTo(reflect.MakeZero(v.Type().(*reflect.PtrType).Elem()))
|
||||
|
|
|
|||
|
|
@ -251,6 +251,8 @@ func stateBeginStringOrEmpty(s *scanner, c int) int {
|
|||
return scanSkipSpace
|
||||
}
|
||||
if c == '}' {
|
||||
n := len(s.parseState)
|
||||
s.parseState[n-1] = parseObjectValue
|
||||
return stateEndValue(s, c)
|
||||
}
|
||||
return stateBeginString(s, c)
|
||||
|
|
@ -289,10 +291,6 @@ func stateEndValue(s *scanner, c int) int {
|
|||
s.step = stateBeginValue
|
||||
return scanObjectKey
|
||||
}
|
||||
if c == '}' {
|
||||
s.popParseState()
|
||||
return scanEndObject
|
||||
}
|
||||
return s.error(c, "after object key")
|
||||
case parseObjectValue:
|
||||
if c == ',' {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue