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

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • bson-4.0.0
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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 (Inactive)
              Reporter:
              Daniel Aprahamian (Inactive)
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: