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

Inconsistent results for BSON.Binary when used with mongodb-extjson on Web

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.0
    • Affects Version/s: None
    • Component/s: BSON

      It seems as if on the web, using BSON.Binary is only possible when using a string that represents the data such that it uses the polyfilled Node.js Buffer. Other than that, the default typed arrays available on browsers do not seem to work as arguments. It seems like the one that should work is Uint8Array and Array. Passing in a Number also does not work but I can't tell if it's supposed to.

      The following code below reproduces the issues listed above. You will need to replace the script sources with your own.

      <script src="file:///Users/eric/Downloads/js-bson/browser_build/bson.js"></script>
      <script type="text/javascript">
      	global.bson = BSON;
      </script>
      <script src="file:///Users/eric/Downloads/mongodb-extjson/dist/bundle.js"></script>
      <script type="text/javascript">
      	global.EJSON = window["mongodb-extjson"];
      </script>
      <script type="text/javascript">
      	console.log(EJSON.stringify(BSON.Binary("foo"))); // works
      	
      	try {
      		console.log(EJSON.stringify(BSON.Binary(5))); // fails but is an instanceof Number (Uncaught RangeError: toString() radix argument must be between 2 and 36)
      	} catch (e) {
      		console.log(e);
      	}
      	console.log(EJSON.stringify(BSON.Binary(new Uint8Array([1, 2, 3])))) // produces incorrect extjson {"$binary":{"base64":"1,2,3","subType":"00"}} (one of accepted String, Buffer, Uint8Array or Array accepted)
      	console.log(EJSON.stringify(BSON.Binary([1, 2, 3]))) // produces incorrect extjson {"$binary":{"base64":"1,2,3","subType":"00"}} (one of accepted String, Buffer, Uint8Array or Array accepted)
      </script>
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            eric.daniels@mongodb.com Eric Daniels (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: