Browse Source

Fixed JSON.parse (object in array).

Dmitry Panov 9 years ago
parent
commit
6594cd5565
2 changed files with 9 additions and 1 deletions
  1. 0 1
      builtin_json.go
  2. 9 0
      runtime_test.go

+ 0 - 1
builtin_json.go

@@ -126,7 +126,6 @@ func (r *Runtime) builtinJSON_decodeArray(d *json.Decoder) (*Object, error) {
 			if delim == ']' {
 			if delim == ']' {
 				break
 				break
 			}
 			}
-			return nil, fmt.Errorf("Unexpected delimiter: %v, expecting ']'", delim)
 		}
 		}
 		value, err := r.builtinJSON_decodeToken(d, tok)
 		value, err := r.builtinJSON_decodeToken(d, tok)
 		if err != nil {
 		if err != nil {

+ 9 - 0
runtime_test.go

@@ -495,6 +495,15 @@ func TestJSONEscape(t *testing.T) {
 	testScript1(SCRIPT, asciiString(`"\\+1"`), t)
 	testScript1(SCRIPT, asciiString(`"\\+1"`), t)
 }
 }
 
 
+func TestJSONObjectInArray(t *testing.T) {
+	const SCRIPT = `
+	var a = "[{\"a\":1},{\"a\":2}]";
+	JSON.stringify(JSON.parse(a)) == a;
+	`
+
+	testScript1(SCRIPT, valueTrue, t)
+}
+
 /*
 /*
 func TestArrayConcatSparse(t *testing.T) {
 func TestArrayConcatSparse(t *testing.T) {
 function foo(a,b,c)
 function foo(a,b,c)