Skip to content

Commit 284ed29

Browse files
author
Isabella Siu
committed
GODRIVER-611 Fix extJSONParser.advanceState() for string in array
Change-Id: Iab003ef689dab676c15353e93b747c1d75fd2d12
1 parent 7b71e6f commit 284ed29

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

bson/bsonrw/extjson_parser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,14 @@ func (ejp *extJSONParser) advanceState() {
468468
}
469469
case jttString:
470470
switch ejp.s {
471-
case jpsSawBeginObject, jpsSawComma:
471+
case jpsSawComma:
472+
if ejp.peekMode() == jpmArrayMode {
473+
ejp.s = jpsSawValue
474+
ejp.v = extendJSONToken(jt)
475+
return
476+
}
477+
fallthrough
478+
case jpsSawBeginObject:
472479
ejp.s = jpsSawKey
473480
ejp.k = jt.v.(string)
474481
return

bson/bsonrw/extjson_parser_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ func TestExtJSONParserAllTypes(t *testing.T) {
451451
, "CodeWithScope" : { "$code": "function() {}", "$scope": { "x": 1 } }
452452
, "EmptySubdocument" : {}
453453
, "Subdocument" : { "foo": "bar", "baz": { "$numberInt": "42" } }
454-
, "Array" : [{"$numberInt": "1"}, {"$numberLong": "2"}, {"$numberDouble": "3"}, 4, 5.0]
454+
, "Array" : [{"$numberInt": "1"}, {"$numberLong": "2"}, {"$numberDouble": "3"}, 4, "string", 5.0]
455455
, "Timestamp" : { "$timestamp": { "t": 42, "i": 1 } }
456456
, "RegularExpression" : { "$regularExpression": { "pattern": "foo*", "options": "ix" } }
457457
, "DatetimeEpoch" : { "$date": { "$numberLong": "0" } }
@@ -572,6 +572,7 @@ func TestExtJSONParserAllTypes(t *testing.T) {
572572
{typ: bsontype.Int64, val: &extJSONValue{t: bsontype.String, v: "2"}},
573573
{typ: bsontype.Double, val: &extJSONValue{t: bsontype.String, v: "3"}},
574574
{typ: bsontype.Int32, val: &extJSONValue{t: bsontype.Int32, v: int32(4)}},
575+
{typ: bsontype.String, val: &extJSONValue{t: bsontype.String, v: "string"}},
575576
{typ: bsontype.Double, val: &extJSONValue{t: bsontype.Double, v: 5.0}},
576577
},
577578
},

0 commit comments

Comments
 (0)