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

Consider adding a "strict" BSON decode option that disallows most/all type conversion

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 2.1.0
    • Affects Version/s: None
    • Component/s: BSON
    • None

      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?

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: