Skip to content

Commit

Permalink
Fix StrListDelete side effect.
Browse files Browse the repository at this point in the history
  • Loading branch information
ncabatoff committed Feb 6, 2024
1 parent b4a7f3e commit 8da5295
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions strutil/strutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/base64"
"encoding/json"
"fmt"
"slices"
"sort"
"strings"
"unicode"
Expand Down Expand Up @@ -367,6 +368,9 @@ func StrListDelete(s []string, d string) []string {

for index, element := range s {
if element == d {
// Using the provided slice as the basis for the return value can
// result in confusing behaviour, see https://go.dev/play/p/EAtNw4lLugu
s = slices.Clone(s)
return append(s[:index], s[index+1:]...)
}
}
Expand Down

0 comments on commit 8da5295

Please sign in to comment.