mirror of
https://github.com/containers/podman.git
synced 2025-11-02 14:55:28 +08:00
Convert Split() calls with an equal sign to SplitN()
After seeing #7759, I decided to look at the calls in Podman and Buildah to see if we had issues with strings.Split() calls where an "=" (equals) sign was in play and we expected to split on only the first one. There were only one or two that I found in here that I think might have been troubling, the remainder are just adding some extra safety. I also had another half dozen or so that were checking length expectations appropriately, those I left alone. Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
This commit is contained in:
@ -82,7 +82,7 @@ func LabelFilter(ctx context.Context, labelfilter string) ResultFilter {
|
||||
// We need to handle both label=key and label=key=value
|
||||
return func(i *Image) bool {
|
||||
var value string
|
||||
splitFilter := strings.Split(labelfilter, "=")
|
||||
splitFilter := strings.SplitN(labelfilter, "=", 2)
|
||||
key := splitFilter[0]
|
||||
if len(splitFilter) > 1 {
|
||||
value = splitFilter[1]
|
||||
@ -157,7 +157,7 @@ func (ir *Runtime) createFilterFuncs(filters []string, img *Image) ([]ResultFilt
|
||||
var filterFuncs []ResultFilter
|
||||
ctx := context.Background()
|
||||
for _, filter := range filters {
|
||||
splitFilter := strings.Split(filter, "=")
|
||||
splitFilter := strings.SplitN(filter, "=", 2)
|
||||
if len(splitFilter) < 2 {
|
||||
return nil, errors.Errorf("invalid filter syntax %s", filter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user