Skip to content

Commit 4bc77e4

Browse files
committed
UPSTREAM: 31353: fix env key-value pair matching
Related BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1369679 Passing key-value pairs to `oc set env` with certain invalid characters causes an unrelated error to be rendered. This is caused because the regex that separates key-value pairs from resource-type/resource arguments does not account for invalid key-value pairs with invalid characters (other than "-"). This means that when a command such as `oc set env rc/node-1 test#abc=1234` is executed, `test#abc=1234` will not be recognized as a key-value pair, and instead be treated as a resource without a resource type, giving a user the wrong reason for command failure. This patch updates the regex matching env key-value pairs to match any character from the beginning of the arg to the equal sign rather than a select amount of characters, ensuring that key-value pair arguments with any kind of invalid character are still recognized as such. \##### Before `$ oc set env rc/node-1 test-@abc=1234` ``` there is no need to specify a resource type as a separate argument when passing arguments in resource/name form (e.g. 'oc get resource/<resource_name>' instead of 'oc get resource resource/<resource_name>' ``` \##### After `$ oc set env rc/node-1 test@-abc=1234` ``` error: ReplicationController "node-1" is invalid: spec.template.spec.containers[0].env[3].name: Invalid value: "test@-abc": must be a C identifier (matching regex [A-Za-z_][A-Za-z0-9_]*): e.g. "my_name" or "MyName" ```
1 parent 7d0ef9e commit 4bc77e4

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/cmd/util/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func GetEnv(key string) (string, bool) {
4141

4242
type Environment map[string]string
4343

44-
var argumentEnvironment = regexp.MustCompile("(?ms)^([\\w\\-_]+)\\=(.*)$")
44+
var argumentEnvironment = regexp.MustCompile("(?ms)^((.*)+)\\=(.*)$")
4545

4646
func IsEnvironmentArgument(s string) bool {
4747
return argumentEnvironment.MatchString(s)

0 commit comments

Comments
 (0)