[CDRIVER-1170] Problem with bson_new_from_json with numberLong = 0 Created: 23/Mar/16  Updated: 03/May/17  Resolved: 23/Mar/16

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: 1.3.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Daly Assignee: A. Jesse Jiryu Davis
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates CDRIVER-1083 bson_ascii_strtoll can't parse "0 " Closed

 Description   

A call to bson_new_from_json with "$numberLong" : "0" fails, while "$numberLong": "1" succeeds.

Here's some test code:

#include <bson.h>
#include <iostream>
#include <string>
 
int main(int argc, char *argv[]) {
  bson_error_t error;
  std::string bad_string = "{\"x\":{\"$numberLong\":\"0\"}}";
  std::string good_string = "{\"x\":{\"$numberLong\":\"1\"}}";
  bson_t *result =
      bson_new_from_json(reinterpret_cast<const uint8_t *>(good_string.data()),
                         good_string.size(), &error);
  if (!result)
    std::cout << "Error on good string" << std::endl;
  else {
    std::cout << "Good string okay" << std::endl;
    bson_destroy(result);
  }
  result =
      bson_new_from_json(reinterpret_cast<const uint8_t *>(bad_string.data()),
                         good_string.size(), &error);
  if (!result)
    std::cout << "Error on bad string" << std::endl;
  else {
    std::cout << "Bad string okay" << std::endl;
    bson_destroy(result);
  }
  return 0;
}

When I run that code on a recent master (26494954a1) of the c driver or r1.3 I get:

Good string okay
Error on bad string

I've been testing on my macbook.



 Comments   
Comment by David Daly [ 23/Mar/16 ]

That does in fact fix it. Thanks. I was sure that I had pulled master and submodule update, but must have had a stale copy.

Comment by A. Jesse Jiryu Davis [ 23/Mar/16 ]

Sounds like CDRIVER-1083, which has been fixed in libbson on master. Ensure you have the latest libbson built – if you're using the bundled libbson in the git submodule "src/libbson", do "git submodule update" to get the latest.

Generated at Wed Feb 07 21:11:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.