Skip to content

Commit 52ee283

Browse files
authored
Fix slice handling in Env.Libraries() (#826)
1 parent ff98bc0 commit 52ee283

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

‎cel/env.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func (e *Env) HasLibrary(libName string) bool {
390390

391391
// Libraries returns a list of SingletonLibrary that have been configured in the environment.
392392
func (e *Env) Libraries() []string {
393-
libraries := make([]string, len(e.libraries))
393+
libraries := make([]string, 0, len(e.libraries))
394394
for libName := range e.libraries {
395395
libraries = append(libraries, libName)
396396
}

‎cel/env_test.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,13 @@ func TestLibraries(t *testing.T) {
238238
t.Errorf("Expected HasLibrary() to return true for '%s'", expected)
239239
}
240240
libMap := map[string]struct{}{}
241-
for _, lib := range e.Libraries() {
241+
libraries := e.Libraries()
242+
for _, lib := range libraries {
242243
libMap[lib] = struct{}{}
243244
}
245+
if len(libraries) != 2 {
246+
t.Errorf("Expected HasLibrary() to contain exactly 2 libraries but got: %v", libraries)
247+
}
244248

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

0 commit comments

Comments
 (0)