Skip to content

Commit 97b1b72

Browse files
benjirewisBenjamin Rewis
authored and
Benjamin Rewis
committed
GODRIVER-2351 Add missing nil option checks (#883)
1 parent 1bef05b commit 97b1b72

File tree

7 files changed

+23
-1
lines changed

7 files changed

+23
-1
lines changed

mongo/collection.go

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

694694
updateOptions := make([]*options.UpdateOptions, 0, len(opts))
695695
for _, opt := range opts {
696+
if opt == nil {
697+
continue
698+
}
696699
uOpts := options.Update()
697700
uOpts.BypassDocumentValidation = opt.BypassDocumentValidation
698701
uOpts.Collation = opt.Collation
@@ -1276,6 +1279,9 @@ func (coll *Collection) FindOne(ctx context.Context, filter interface{},
12761279

12771280
findOpts := make([]*options.FindOptions, 0, len(opts))
12781281
for _, opt := range opts {
1282+
if opt == nil {
1283+
continue
1284+
}
12791285
findOpts = append(findOpts, &options.FindOptions{
12801286
AllowPartialResults: opt.AllowPartialResults,
12811287
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ func newConnectionConfig(opts ...ConnectionOption) (*connectionConfig, error) {
6767
}
6868

6969
for _, opt := range opts {
70+
if opt == nil {
71+
continue
72+
}
73+
7074
err := opt(cfg)
7175
if err != nil {
7276
return nil, err

x/mongo/driver/topology/server_options.go

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

4848
for _, opt := range opts {
49+
if opt == nil {
50+
continue
51+
}
4952
err := opt(cfg)
5053
if err != nil {
5154
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)