Skip to content

Commit bddde89

Browse files
committed
GODRIVER-1919 Add object id decoder awareness of string hex
1 parent 0af4510 commit bddde89

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

bson/bsoncodec/default_value_decoders.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,9 @@ func (dvd DefaultValueDecoders) objectIDDecodeType(dc DecodeContext, vr bsonrw.V
740740
if err != nil {
741741
return emptyValue, err
742742
}
743+
if oid, err = primitive.ObjectIDFromHex(str); err == nil {
744+
break
745+
}
743746
if len(str) != 12 {
744747
return emptyValue, fmt.Errorf("an ObjectID string must be exactly 12 bytes long (got %v)", len(str))
745748
}

bson/bsoncodec/default_value_decoders_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,17 @@ func TestDefaultValueDecoders(t *testing.T) {
11181118
bsonrwtest.ReadString,
11191119
nil,
11201120
},
1121+
{
1122+
"success/string-hex",
1123+
primitive.ObjectID{0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62},
1124+
nil,
1125+
&bsonrwtest.ValueReaderWriter{
1126+
BSONType: bsontype.String,
1127+
Return: "303132333435363738396162",
1128+
},
1129+
bsonrwtest.ReadString,
1130+
nil,
1131+
},
11211132
{
11221133
"decode null",
11231134
primitive.ObjectID{},

0 commit comments

Comments
 (0)