Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1737

BSON ObjectID constructor should throw if passed-in string uses characters greater than 8 bits.

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
      None

      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=char

      The 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

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: