]> Cypherpunks repositories - gostls13.git/commitdiff
json: object members must have a value
authorAnthony Martin <ality@pbrane.org>
Wed, 4 Aug 2010 00:05:00 +0000 (17:05 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 4 Aug 2010 00:05:00 +0000 (17:05 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/1847050

src/pkg/json/decode_test.go
src/pkg/json/scanner.go

index d5ab29ca6411c7df36bb41b2fc758085f3bddbbb..0aa269743fe4a7c8e4b7a5ebc825ff0b22874109 100644 (file)
@@ -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,7 +78,12 @@ func TestUnmarshal(t *testing.T) {
        for i, tt := range unmarshalTests {
                in := []byte(tt.in)
                if err := checkValid(in, &scan); err != nil {
-                       t.Errorf("#%d: checkValid: %v", i, err)
+                       if !reflect.DeepEqual(err, tt.err) {
+                               t.Errorf("#%d: checkValid: %v", i, err)
+                               continue
+                       }
+               }
+               if tt.ptr == nil {
                        continue
                }
                // v = new(right-type)
index 27c5ffb7a4da2a49631e4be6c72dd72cfcd6f8c0..584231ef00f21f1a78c55336877d700713c62094 100644 (file)
@@ -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 == ',' {