Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-1919 Add object id decoder awareness of string hex #610

Merged
merged 2 commits into from Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions bson/bsoncodec/default_value_decoders.go
Expand Up @@ -740,6 +740,9 @@ func (dvd DefaultValueDecoders) objectIDDecodeType(dc DecodeContext, vr bsonrw.V
if err != nil {
return emptyValue, err
}
if oid, err = primitive.ObjectIDFromHex(str); err == nil {
divjotarora marked this conversation as resolved.
Show resolved Hide resolved
break
}
if len(str) != 12 {
return emptyValue, fmt.Errorf("an ObjectID string must be exactly 12 bytes long (got %v)", len(str))
}
Expand Down
11 changes: 11 additions & 0 deletions bson/bsoncodec/default_value_decoders_test.go
Expand Up @@ -1118,6 +1118,17 @@ func TestDefaultValueDecoders(t *testing.T) {
bsonrwtest.ReadString,
nil,
},
{
"success/string-hex",
primitive.ObjectID{0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62},
nil,
&bsonrwtest.ValueReaderWriter{
BSONType: bsontype.String,
Return: "303132333435363738396162",
},
bsonrwtest.ReadString,
nil,
},
{
"decode null",
primitive.ObjectID{},
Expand Down