[GODRIVER-2788] Consider adding a "strict" BSON decode option that disallows most/all type conversion Created: 31/Mar/23  Updated: 08/Jan/24

Status: Backlog
Project: Go Driver
Component/s: BSON
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Go Driver 2.0 BSON
Quarter: FY24Q3

 Description   

Currently the Go driver BSON decoder will decode many types, including BSON booleans, into Go booleans. The current rules are:

  • BSON boolean - Match the BSON boolean value.
  • BSON int32 - Any non-zero value is Go true.
  • BSON int64 - Any non-zero value is Go true.
  • BSON double - Any non-zero value is Go true.
  • BSON null - Always Go false.
  • BSON undefined - Always Go false.
    Check out an example here.

However, other drivers for statically typed languages (e.g. Rust) only allow strict BSON boolean -> native boolean decoding. Update the Go behavior to default to strict BSON boolean -> Go boolean decoding. Add a decoder option that enables "strict" decoding that prevents implicit type conversion.

Open questions:

  • Should we keep the existing behavior as the default and add a configuration option that only allows strict value type assignment? Or should we update the default to be strict?
  • Should we also disallow implicit type conversion for numeric types?
  • What motivated this?

Definition of done:

  • Add an option to bson.Decoder that requires "strict" BSON -> Go type decoding behavior.
    • What types should this apply to? Boolean only? Integer and float also?

Generated at Thu Feb 08 08:39:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.