Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-1366

libbson has different behavior when parsing a special type at the top level

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.4.0
    • Affects Version/s: None
    • Component/s: json, libbson
    • None

      Libbson has different behavior while parsing a MongoDB Extended JSON type at the top level (without a key). The behavior depends on the presence of other keys.

      In this example I'm using "$numberLong" but the same behavior is reproducible with other special types.

      (python2.6) ➜  python-bsonjs git:(master) ✗ python
      Python 2.6.9 (unknown, Oct 23 2015, 19:19:20)
      [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
      Type "help", "copyright", "credits" or "license" for more information.
      >>> import bsonjs
      >>> print(bsonjs.loads.__doc__)
      load(json) -> bytes
      
      Encode `json` (a `str` or `bytes-like object` containing a MongoDB Extended
      JSON document) to BSON bytes.
      This function wraps `bson_init_from_json` from libbson.
      >>> bsonjs.loads('{"$numberLong": "1"}')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      ValueError: Invalid MongoDB extended JSON
      >>> bsonjs.loads('{"$numberLong": "1", "a": 1}')
      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      ValueError: Invalid key a": 1}.  Looking for values for 18
      >>> bsonjs.loads('{"a": 1, "$numberLong": "1"}')
      '\x1f\x00\x00\x00\x10a\x00\x01\x00\x00\x00\x02$numberLong\x00\x02\x00\x00\x001\x00\x00'
      >>> bsonjs.loads('{"a": 1, "$numberLong": "1", "a": 1}')
      '&\x00\x00\x00\x10a\x00\x01\x00\x00\x00\x02$numberLong\x00\x02\x00\x00\x001\x00\x10a\x00\x01\x00\x00\x00\x00'
      

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: