From 52821d0af38845ce12b2fb4d612c97eec829daf1 Mon Sep 17 00:00:00 2001 From: sahithiharness Date: Tue, 26 Mar 2024 22:52:01 +0530 Subject: [PATCH] fix: [CI-10905]: fixed the key name with '-' --- fixtures/exported.env | 1 + godotenv_test.go | 17 +++++++++-------- parser.go | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/fixtures/exported.env b/fixtures/exported.env index 5821377..a964bb5 100644 --- a/fixtures/exported.env +++ b/fixtures/exported.env @@ -1,2 +1,3 @@ export OPTION_A=2 export OPTION_B='\n' +export OPTION-C=123#12 diff --git a/godotenv_test.go b/godotenv_test.go index c6d7e54..33b7a28 100644 --- a/godotenv_test.go +++ b/godotenv_test.go @@ -170,6 +170,7 @@ func TestLoadExportedEnv(t *testing.T) { expectedValues := map[string]string{ "OPTION_A": "2", "OPTION_B": "\\n", + "OPTION-C": "123#12", } loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) @@ -582,42 +583,42 @@ func TestWhitespace(t *testing.T) { }{ "Leading whitespace": { input: " A=a\n", - key: "A", + key: "A", value: "a", }, "Leading tab": { input: "\tA=a\n", - key: "A", + key: "A", value: "a", }, "Leading mixed whitespace": { input: " \t \t\n\t \t A=a\n", - key: "A", + key: "A", value: "a", }, "Leading whitespace before export": { input: " \t\t export A=a\n", - key: "A", + key: "A", value: "a", }, "Trailing whitespace": { input: "A=a \t \t\n", - key: "A", + key: "A", value: "a", }, "Trailing whitespace with export": { input: "export A=a\t \t \n", - key: "A", + key: "A", value: "a", }, "No EOL": { input: "A=a", - key: "A", + key: "A", value: "a", }, "Trailing whitespace with no EOL": { input: "A=a ", - key: "A", + key: "A", value: "a", }, } diff --git a/parser.go b/parser.go index cc709af..1a9e034 100644 --- a/parser.go +++ b/parser.go @@ -96,7 +96,7 @@ loop: case '_': default: // variable name should match [A-Za-z0-9_.] - if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || rchar == '.' { + if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || rchar == '.' || rchar == '-' { continue }