From 5cc16e098c3062cb4ae3f5062e004ee0cc535988 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 20 Dec 2021 22:13:06 +0100 Subject: [PATCH] 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. --- cmd/common-main.go | 16 ++++++++++++++-- cmd/common-main_test.go | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmd/common-main.go b/cmd/common-main.go index 6903fce36..770efb202 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -460,9 +460,21 @@ func parsEnvEntry(envEntry string) (envKV, error) { if len(envTokens) != 2 { 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{ - Key: envTokens[0], - Value: envTokens[1], + Key: key, + Value: val, }, nil } diff --git a/cmd/common-main_test.go b/cmd/common-main_test.go index b22abc6a6..1b57a9e8b 100644 --- a/cmd/common-main_test.go +++ b/cmd/common-main_test.go @@ -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_PASSWORD=minio123`,