Skip to content

Commit 32aba96

Browse files
author
Divjot Arora
authored
GODRIVER-1502 Fix variable shadowing in parsing (#332)
1 parent 1910bcf commit 32aba96

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

bson/bsonrw/extjson_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
118118
switch t {
119119
case bsontype.JavaScript:
120120
// just saw $code, need to check for $scope at same level
121-
_, err := ejp.readValue(bsontype.JavaScript)
122-
121+
_, err = ejp.readValue(bsontype.JavaScript)
123122
if err != nil {
124123
break
125124
}
@@ -128,6 +127,7 @@ func (ejp *extJSONParser) peekType() (bsontype.Type, error) {
128127
case jpsSawEndObject: // type is TypeJavaScript
129128
case jpsSawComma:
130129
ejp.advanceState()
130+
131131
if ejp.s == jpsSawKey && ejp.k == "$scope" {
132132
t = bsontype.CodeWithScope
133133
} else {

bson/bsonrw/extjson_parser_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func TestExtJSONParserPeekType(t *testing.T) {
148148
errFs: []expectedErrorFunc{expectNoError, expectError},
149149
},
150150
makeInvalidTestCase("lone $scope", `{"$scope": {}}`, expectError),
151+
makeInvalidTestCase("empty code with unknown extra key", `{"$code":"", "0":""}`, expectError),
152+
makeInvalidTestCase("non-empty code with unknown extra key", `{"$code":"foobar", "0":""}`, expectError),
151153
}
152154

153155
for _, tc := range cases {

0 commit comments

Comments
 (0)