env: Remove quotes when parsing a config env file (#13953)

The code parsing the config environment file does not remove 
quotes of environment variables values. This commit adds this 
capability.
This commit is contained in:
Anis Elleuch 2021-12-20 22:13:06 +01:00 committed by GitHub
parent 364e27d5f2
commit 5cc16e098c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View File

@ -460,9 +460,21 @@ func parsEnvEntry(envEntry string) (envKV, error) {
if len(envTokens) != 2 { if len(envTokens) != 2 {
return envKV{}, fmt.Errorf("envEntry malformed; %s, expected to be of form 'KEY=value'", envEntry) return envKV{}, fmt.Errorf("envEntry malformed; %s, expected to be of form 'KEY=value'", envEntry)
} }
key := envTokens[0]
val := envTokens[1]
// Remove quotes from the value if found
if len(val) >= 2 {
quote := val[0]
if (quote == '"' || quote == '\'') && val[len(val)-1] == quote {
val = val[1 : len(val)-1]
}
}
return envKV{ return envKV{
Key: envTokens[0], Key: key,
Value: envTokens[1], Value: val,
}, nil }, nil
} }

View File

@ -45,6 +45,26 @@ export MINIO_ROOT_PASSWORD=minio123`,
}, },
}, },
}, },
// Value with double quotes
{`export MINIO_ROOT_USER="minio"`,
false,
[]envKV{
{
Key: "MINIO_ROOT_USER",
Value: "minio",
},
},
},
// Value with single quotes
{`export MINIO_ROOT_USER='minio'`,
false,
[]envKV{
{
Key: "MINIO_ROOT_USER",
Value: "minio",
},
},
},
{` {`
MINIO_ROOT_USER=minio MINIO_ROOT_USER=minio
MINIO_ROOT_PASSWORD=minio123`, MINIO_ROOT_PASSWORD=minio123`,