Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-756

Incorrect formatting of numbers with exponents in JSON

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 0.3.0
    • Affects Version/s: 0.1.0
    • Component/s: JSON & ExtJSON
    • None
    • Environment:
      All

      When a number is converted to a string for output to JSON there is a case where the number can be corrupted.  This occurs when the number has a single significant digit AND an exponent.  For example, the number 3E-5 is corrupted to "3E-5.0".  The affected lines are here:

      https://github.com/mongodb/mongo-go-driver/blob/master/bson/bson.go#L78

      And here:

      https://github.com/mongodb/mongo-go-driver/blob/master/bson/bsonrw/extjson_writer.go#L624

      This can be fixed this by changing:

      if !strings.ContainsRune(s, '.') {

      to:

      if !strings.ContainsRune(s, 'E') && !strings.ContainsRune(s, '.') {

      But maybe there is a better way...
       

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            slugh23 John
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: