From a3e317773a2b90a433136e1ff2a8394bc5017c75 Mon Sep 17 00:00:00 2001 From: Lenin Alevski Date: Thu, 7 Apr 2022 16:02:51 -0700 Subject: [PATCH] Skip commented lines when parsing MinIO configuration file (#14710) Signed-off-by: Lenin Alevski --- cmd/common-main.go | 7 +++++++ cmd/common-main_test.go | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cmd/common-main.go b/cmd/common-main.go index 0b9ea911d..ea9fda5b4 100644 --- a/cmd/common-main.go +++ b/cmd/common-main.go @@ -487,6 +487,13 @@ func parsEnvEntry(envEntry string) (envKV, error) { key := envTokens[0] val := envTokens[1] + if strings.HasPrefix(key, "#") { + // Skip commented lines + return envKV{ + Skip: true, + }, nil + } + // Remove quotes from the value if found if len(val) >= 2 { quote := val[0] diff --git a/cmd/common-main_test.go b/cmd/common-main_test.go index f7abdfb9a..b5c0b5518 100644 --- a/cmd/common-main_test.go +++ b/cmd/common-main_test.go @@ -134,6 +134,24 @@ export MINIO_ROOT_PASSWORD=minio123`, true, nil, }, + { + ` +# MINIO_ROOT_USER=minioadmin +# MINIO_ROOT_PASSWORD=minioadmin +MINIO_ROOT_USER=minio +MINIO_ROOT_PASSWORD=minio123`, + false, + []envKV{ + { + Key: "MINIO_ROOT_USER", + Value: "minio", + }, + { + Key: "MINIO_ROOT_PASSWORD", + Value: "minio123", + }, + }, + }, } for _, testCase := range testCases { testCase := testCase @@ -153,6 +171,11 @@ export MINIO_ROOT_PASSWORD=minio123`, if err == nil && testCase.expectedErr { t.Error(errors.New("expected error, found success")) } + + if len(ekvs) != len(testCase.expectedEkvs) { + t.Errorf("expected %v keys, got %v keys", len(testCase.expectedEkvs), len(ekvs)) + } + if !reflect.DeepEqual(ekvs, testCase.expectedEkvs) { t.Errorf("expected %v, got %v", testCase.expectedEkvs, ekvs) }