Skip to content

Commit b7e1199

Browse files
authored
Merge pull request #7040 from killianmuldoon/fix/nil-pointer-patch-option
🐛 Fix nil pointer in patch Apply
2 parents 275670a + ab93cc3 commit b7e1199

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

util/conditions/patch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func (p Patch) Apply(latest Setter, options ...ApplyOption) error {
134134

135135
applyOpt := &applyOptions{}
136136
for _, o := range options {
137+
if util.IsNil(o) {
138+
return errors.New("error patching conditions: ApplyOption was nil")
139+
}
137140
o(applyOpt)
138141
}
139142

util/conditions/patch_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ func TestApply(t *testing.T) {
283283
want: conditionList(fooFalse), // after condition should be kept in case of error
284284
wantErr: false,
285285
},
286+
{
287+
name: "Error when nil passed as an ApplyOption",
288+
before: getterWithConditions(fooTrue),
289+
after: getterWithConditions(fooFalse),
290+
latest: setterWithConditions(),
291+
options: []ApplyOption{nil},
292+
wantErr: true,
293+
},
286294
}
287295

288296
for _, tt := range tests {

0 commit comments

Comments
 (0)