Skip to content

Commit

Permalink
Prevent self-append for Issues (#988)
Browse files Browse the repository at this point in the history
  • Loading branch information
TristonianJones authored Jul 30, 2024
1 parent 25457de commit 5cbef66
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cel/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,10 @@ func (i *Issues) Append(other *Issues) *Issues {
if i == nil {
return other
}
if other == nil {
if other == nil || i == other {
return i
}
return NewIssues(i.errs.Append(other.errs.GetErrors()))
return NewIssuesWithSourceInfo(i.errs.Append(other.errs.GetErrors()), i.info)
}

// String converts the issues to a suitable display string.
Expand Down
15 changes: 15 additions & 0 deletions cel/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ func TestIssuesEmpty(t *testing.T) {
}
}

func TestIssuesAppendSelf(t *testing.T) {
e, err := NewEnv()
if err != nil {
t.Fatalf("NewEnv() failed: %v", err)
}
_, iss := e.Compile("a")
if len(iss.Errors()) != 1 {
t.Errorf("iss.Errors() got %v, wanted 1 error", iss.Errors())
}
iss = iss.Append(iss)
if len(iss.Errors()) != 1 {
t.Errorf("iss.Errors() got %v, wanted 1 error", iss.Errors())
}
}

func TestIssues(t *testing.T) {
e, err := NewEnv()
if err != nil {
Expand Down

0 comments on commit 5cbef66

Please sign in to comment.