From 5cbef66be0ac05f0a971456e3fa6df6e4cfd52a0 Mon Sep 17 00:00:00 2001 From: Tristan Swadell Date: Tue, 30 Jul 2024 13:08:05 -0700 Subject: [PATCH] Prevent self-append for Issues (#988) --- cel/env.go | 4 ++-- cel/env_test.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cel/env.go b/cel/env.go index 17c52180..3af2b36f 100644 --- a/cel/env.go +++ b/cel/env.go @@ -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. diff --git a/cel/env_test.go b/cel/env_test.go index 3c3235c5..3fbdeac0 100644 --- a/cel/env_test.go +++ b/cel/env_test.go @@ -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 {