Negative zero not handled properly in extended JSON

XMLWordPrintableJSON

    • Type: Sub-task
    • Resolution: Fixed
    • Priority: Minor - P4
    • bson-5.0.0
    • Affects Version/s: bson-4.6.5
    • Component/s: EJSON
    • 3
    • Not Needed
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      What problem are you facing?

      Spec tests say -0 should be serialized to EJSON differently from +0:

      https://github.com/mongodb/specifications/blob/bafb024be8202b1676a3c6632e8a3eb9cf36209b/source/bson-corpus/tests/double.json#L42-L53

      This isn’t something that’s easily fixable for the relaxed EJSON, since JSON.stringify(-0) === '0', but should be fixable for canonical EJSON.

      (This only occurs with -0 JS numbers, not Double(-0) bson objects.)

      What driver and relevant dependency versions are you using?

      Latest js-bson (4.6.5).

      Steps to reproduce?

      > EJSON.stringify({ neg: -0, pos: 0 }, { relaxed: false })
      '{"neg":{"$numberInt":"0"},"pos":{"$numberInt":"0"}}'
      

            Assignee:
            Neal Beeken
            Reporter:
            Anna Henningsen
            Bailey Pearson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: