diff --git a/dotenv/fixtures/special.env b/dotenv/fixtures/special.env new file mode 100644 index 00000000..5499b0cd --- /dev/null +++ b/dotenv/fixtures/special.env @@ -0,0 +1,3 @@ +VAR.WITH.DOTS=dots +VAR_WITH_UNDERSCORES=underscores +VAR-WITH-DASHES=dashes diff --git a/dotenv/godotenv_test.go b/dotenv/godotenv_test.go index da2265c1..163941df 100644 --- a/dotenv/godotenv_test.go +++ b/dotenv/godotenv_test.go @@ -718,3 +718,11 @@ func TestUTF8BOM(t *testing.T) { loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets) } + +func TestDash(t *testing.T) { + loadEnvAndCompareValues(t, Load, "fixtures/special.env", map[string]string{ + "VAR-WITH-DASHES": "dashes", + "VAR.WITH.DOTS": "dots", + "VAR_WITH_UNDERSCORES": "underscores", + }, noopPresets) +} diff --git a/dotenv/parser.go b/dotenv/parser.go index 9a8d0f60..84347e31 100644 --- a/dotenv/parser.go +++ b/dotenv/parser.go @@ -108,9 +108,9 @@ loop: offset = i + 1 inherited = char == '\n' break loop - case '_', '.': + case '_', '.', '-': default: - // variable name should match [A-Za-z0-9_.] + // variable name should match [A-Za-z0-9_.-] if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) { continue }