forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containers#21549 from openshift-cherrypick-robot/c…
…herry-pick-20657-to-v4.9 [v4.9] RHEL-14922: accept a config blob alongside the "changes" slice when committing
- Loading branch information
Showing
19 changed files
with
330 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package handlers | ||
|
||
import ( | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
// DecodeChanges reads one or more changes from a slice and cleans them up, | ||
// since what we've advertised as being acceptable in the past isn't really. | ||
func DecodeChanges(changes []string) []string { | ||
result := make([]string, 0, len(changes)) | ||
for _, possiblyMultilineChange := range changes { | ||
for _, change := range strings.Split(possiblyMultilineChange, "\n") { | ||
// In particular, we document that we accept values | ||
// like "CMD=/bin/sh", which is not valid Dockerfile | ||
// syntax, so we can't just pass such a value directly | ||
// to a parser that's going to rightfully reject it. | ||
// If we trim the string of whitespace at both ends, | ||
// and the first occurrence of "=" is before the first | ||
// whitespace, replace that "=" with whitespace. | ||
change = strings.TrimSpace(change) | ||
if change == "" { | ||
continue | ||
} | ||
firstEqualIndex := strings.Index(change, "=") | ||
firstSpaceIndex := strings.IndexFunc(change, unicode.IsSpace) | ||
if firstEqualIndex != -1 && (firstSpaceIndex == -1 || firstEqualIndex < firstSpaceIndex) { | ||
change = change[:firstEqualIndex] + " " + change[firstEqualIndex+1:] | ||
} | ||
result = append(result, change) | ||
} | ||
} | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package handlers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDecodeChanges(t *testing.T) { | ||
testCases := []struct { | ||
description string | ||
input string | ||
output []string | ||
}{ | ||
{ | ||
description: "nothing", | ||
input: "", | ||
output: []string{}, | ||
}, | ||
{ | ||
description: "space", | ||
input: `CMD=/bin/bash`, | ||
output: []string{"CMD /bin/bash"}, | ||
}, | ||
{ | ||
description: "equal", | ||
input: `CMD=/bin/bash`, | ||
output: []string{"CMD /bin/bash"}, | ||
}, | ||
{ | ||
description: "both-but-right-first", | ||
input: `LABEL A=B`, | ||
output: []string{"LABEL A=B"}, | ||
}, | ||
{ | ||
description: "both-but-right-second", | ||
input: `LABEL A=B C=D`, | ||
output: []string{"LABEL A=B C=D"}, | ||
}, | ||
{ | ||
description: "both-but-wrong", | ||
input: `LABEL=A=B C=D`, | ||
output: []string{"LABEL A=B C=D"}, | ||
}, | ||
} | ||
for _, testCase := range testCases { | ||
t.Run(testCase.description, func(t *testing.T) { | ||
output := DecodeChanges([]string{testCase.input}) | ||
assert.Equalf(t, testCase.output, output, "decoded value was not what we expected") | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.