Skip to content

Commit 3fd6261

Browse files
authored
Changed order of actions in ObjectIDFromHex func (#637)
1 parent 29b591c commit 3fd6261

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

bson/primitive/objectid.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func (id ObjectID) IsZero() bool {
7373
// ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a
7474
// valid ObjectID.
7575
func ObjectIDFromHex(s string) (ObjectID, error) {
76+
if len(s) != 24 {
77+
return NilObjectID, ErrInvalidHex
78+
}
79+
7680
b, err := hex.DecodeString(s)
7781
if err != nil {
7882
return NilObjectID, err
7983
}
8084

81-
if len(b) != 12 {
82-
return NilObjectID, ErrInvalidHex
83-
}
84-
8585
var oid [12]byte
8686
copy(oid[:], b[:])
8787

0 commit comments

Comments
 (0)