Skip to content

Commit a6626e6

Browse files
authored
GODRIVER-2351 Add missing nil option checks (#883)
1 parent 57747f8 commit a6626e6

File tree

7 files changed

+22
-1
lines changed

7 files changed

+22
-1
lines changed

mongo/collection.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,9 @@ func (coll *Collection) ReplaceOne(ctx context.Context, filter interface{},
708708

709709
updateOptions := make([]*options.UpdateOptions, 0, len(opts))
710710
for _, opt := range opts {
711+
if opt == nil {
712+
continue
713+
}
711714
uOpts := options.Update()
712715
uOpts.BypassDocumentValidation = opt.BypassDocumentValidation
713716
uOpts.Collation = opt.Collation
@@ -1312,6 +1315,9 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
13121315

13131316
findOpts := make([]*options.FindOptions, 0, len(opts))
13141317
for _, opt := range opts {
1318+
if opt == nil {
1319+
continue
1320+
}
13151321
findOpts = append(findOpts, &options.FindOptions{
13161322
AllowPartialResults: opt.AllowPartialResults,
13171323
BatchSize: opt.BatchSize,

mongo/options/indexoptions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ func MergeIndexOptions(opts ...*IndexOptions) *IndexOptions {
389389
i := Index()
390390

391391
for _, opt := range opts {
392+
if opt == nil {
393+
continue
394+
}
392395
if opt.Background != nil {
393396
i.Background = opt.Background
394397
}

mongo/options/listdatabasesoptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (ld *ListDatabasesOptions) SetAuthorizedDatabases(b bool) *ListDatabasesOpt
4040
func MergeListDatabasesOptions(opts ...*ListDatabasesOptions) *ListDatabasesOptions {
4141
ld := ListDatabases()
4242
for _, opt := range opts {
43-
if opts == nil {
43+
if opt == nil {
4444
continue
4545
}
4646
if opt.NameOnly != nil {

mongo/readpref/readpref.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func New(mode Mode, opts ...Option) (*ReadPref, error) {
6565
}
6666

6767
for _, opt := range opts {
68+
if opt == nil {
69+
continue
70+
}
6871
err := opt(rp)
6972
if err != nil {
7073
return nil, err

x/mongo/driver/topology/connection_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ func newConnectionConfig(opts ...ConnectionOption) *connectionConfig {
6666
}
6767

6868
for _, opt := range opts {
69+
if opt == nil {
70+
continue
71+
}
6972
opt(cfg)
7073
}
7174

x/mongo/driver/topology/server_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func newServerConfig(opts ...ServerOption) (*serverConfig, error) {
4949
}
5050

5151
for _, opt := range opts {
52+
if opt == nil {
53+
continue
54+
}
5255
err := opt(cfg)
5356
if err != nil {
5457
return nil, err

x/mongo/driver/topology/topology_options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ func newConfig(opts ...Option) (*config, error) {
4848
}
4949

5050
for _, opt := range opts {
51+
if opt == nil {
52+
continue
53+
}
5154
err := opt(cfg)
5255
if err != nil {
5356
return nil, err

0 commit comments

Comments
 (0)