-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: BSON
-
None
-
Empty show more show less
Ported from https://github.com/mongodb/js-bson/issues/281
There have been some similar issues open for this before (#106, #112), but I don't think they made the right point.
The issue happens indeed because the argument is not validated.Providing new ObjectId('000000000000') gives the correct console.log of: 303030303030303030303030.
Javascript strings are UTF-16 encoded. I create my ObjectId using:
new ObjectId('ŽŽŽŽŽŽŽŽŽŽŽŽ')
where Ž is this latin letter http://www.ltg.ed.ac.uk/~richard/utf-8.cgi?input=%C5%BD&mode=charThe construction doesn't fail, but while trying to console.log this ObjectId gives:
undefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefinedundefined
To fix this, we should throw if a length-12 string is passed in with characters with a charCode > 256