Skip to content

Commit 57fd042

Browse files
committed
Fix decoding of JavaScriptCodeWithScope
Read the first i32 off the code_w_s
1 parent 7ea4cc7 commit 57fd042

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/decoder/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ fn decode_bson<R: Read + ?Sized>(reader: &mut R, tag: u8) -> DecoderResult<Bson>
152152
},
153153
Some(JavaScriptCode) => read_string(reader).map(Bson::JavaScriptCode),
154154
Some(JavaScriptCodeWithScope) => {
155+
// disregard the length:
156+
// using Read::take causes infinite type recursion
157+
try!(read_i32(reader));
158+
155159
let code = try!(read_string(reader));
156160
let scope = try!(decode_document(reader));
157161
Ok(Bson::JavaScriptCodeWithScope(code, scope))

tests/modules/encoder_decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ fn test_encode_decode_javascript_code_with_scope() {
148148

149149
assert_eq!(buf, dst);
150150

151-
//let decoded = decode_document(&mut Cursor::new(buf)).unwrap();
152-
//assert_eq!(decoded, doc);
151+
let decoded = decode_document(&mut Cursor::new(buf)).unwrap();
152+
assert_eq!(decoded, doc);
153153
}
154154

155155
#[test]

0 commit comments

Comments
 (0)