[GODRIVER-756] Incorrect formatting of numbers with exponents in JSON Created: 08/Jan/19 Updated: 28/Oct/23 Resolved: 30/Jan/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | JSON & ExtJSON |
| Affects Version/s: | 0.1.0 |
| Fix Version/s: | 0.3.0 |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | John | Assignee: | Isabella Siu (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
All |
||
| Description |
|
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... |