Problem with bson_new_from_json with numberLong = 0

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.3.0
    • Component/s: libbson
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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.

              Assignee:
              A. Jesse Jiryu Davis
              Reporter:
              David Daly (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: