Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #825: Fix slice handling in Env.Libraries() #826

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cel/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (e *Env) HasLibrary(libName string) bool {

// Libraries returns a list of SingletonLibrary that have been configured in the environment.
func (e *Env) Libraries() []string {
libraries := make([]string, len(e.libraries))
libraries := make([]string, 0, len(e.libraries))
for libName := range e.libraries {
libraries = append(libraries, libName)
}
Expand Down
6 changes: 5 additions & 1 deletion cel/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,13 @@ func TestLibraries(t *testing.T) {
t.Errorf("Expected HasLibrary() to return true for '%s'", expected)
}
libMap := map[string]struct{}{}
for _, lib := range e.Libraries() {
libraries := e.Libraries()
for _, lib := range libraries {
libMap[lib] = struct{}{}
}
if len(libraries) != 2 {
t.Errorf("Expected HasLibrary() to contain exactly 2 libraries but got: %v", libraries)
}

if _, ok := libMap[expected]; !ok {
t.Errorf("Expected Libraries() to include '%s'", expected)
Expand Down