Skip to content

Commit 4abcab6

Browse files
author
Divjot Arora
committed
GODRIVER-1502 Fix variable shadowing in parsing
1 parent 4898271 commit 4abcab6

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

bson/bsonrw/extjson_parser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,16 @@ 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-
123-
if err != nil {
121+
_, tempErr := ejp.readValue(bsontype.JavaScript)
122+
if tempErr != nil {
124123
break
125124
}
126125

127126
switch ejp.s {
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)