Unmarshal() should not fail when unmarshaling null to Raw

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • 2.6.1
    • Affects Version/s: None
    • Component/s: BSON
    • None
    • None
    • Go Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      Detailed steps to reproduce the problem?

      package main
      
      import (
      	"fmt"
      
      	"go.mongodb.org/mongo-driver/v2/bson"
      )
      
      func main() {
      	doc := bson.D{{"foo", nil}}
      	raw, _ := bson.Marshal(doc)
      
      	var val struct {
      		Foo bson.Raw
      	}
      	err := bson.Unmarshal(raw, &val)
      	assert.NoError(t, err)
      	assert.Nil(t, val.Foo)
      }
      

      The current implementation returns an error: error decoding key foo: cannot decode null into a bson.Raw

      Definition of done: what must be done to consider the task complete?

      Null should be unmarshalled to a nil bson.Raw. Add tests to cover this scenario.

      The exact Go version used, with patch level:

      The exact version of the Go driver used:

      The issue was introduced in https://github.com/mongodb/mongo-go-driver/pull/2318, and release in 2.5.1

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      na

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      na

      Security Vulnerabilities

      If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here

            Assignee:
            Qingyang Hu
            Reporter:
            Qingyang Hu
            Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: