-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dbPointer): fix utf8 bug for dbPointer
- Loading branch information
1 parent
6f30b4e
commit 018c769
Showing
2 changed files
with
61 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
'use strict'; | ||
|
||
const BSON = require('../../lib/bson'); | ||
const expect = require('chai').expect; | ||
|
||
// 0x0C foo\0 \0\0\07 String.fromCharCode(0x41, 0x42, 0xfffd, 0x43, 0x44) 12 | ||
const bsonSnippet = Buffer.from([ | ||
// Size | ||
34, | ||
0, | ||
0, | ||
0, | ||
// BSON type for DBPointer | ||
0x0c, | ||
|
||
// CString Label Foo | ||
0x66, | ||
0x6f, | ||
0x6f, | ||
0, | ||
|
||
// Length of UTF8 string "AB�CD" | ||
8, | ||
0, | ||
0, | ||
0, | ||
0x41, | ||
0x42, | ||
0xef, | ||
0xbf, | ||
0xbd, | ||
0x43, | ||
0x44, | ||
0, | ||
|
||
// 12-bit pointer | ||
1, | ||
2, | ||
3, | ||
4, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10, | ||
11, | ||
12, | ||
|
||
// null terminator | ||
0 | ||
]); | ||
|
||
describe('dbpointer tests', function() { | ||
it('can serialize and deserialize 0xFFFD in dbpointer name', function() { | ||
expect(() => BSON.deserialize(bsonSnippet)).to.not.throw(); | ||
}); | ||
}); |