Version 1.4.0 allowed hyphen "-" to be in environment variable names, after 1.4.0 this resulted in a parsing error which breaks backwards compatibility. Added back in hyphen support in variable names with associated test cases.

This commit is contained in:
James Wert
2025-03-31 09:33:48 -04:00
parent 3a7a190201
commit 82194f2733
3 changed files with 15 additions and 2 deletions
+3
View File
@@ -0,0 +1,3 @@
OPTION_A=abc
OPTION-B=def
+10
View File
@@ -184,6 +184,16 @@ func TestLoadEqualsEnv(t *testing.T) {
loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)
}
func TestLoadHyphenEnv(t *testing.T) {
envFileName := "fixtures/hyphen.env"
expectedValues := map[string]string{
"OPTION_A": "abc",
"OPTION-B": "def",
}
loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)
}
func TestLoadQuotedEnv(t *testing.T) {
envFileName := "fixtures/quoted.env"
expectedValues := map[string]string{
+2 -2
View File
@@ -96,8 +96,8 @@ loop:
break loop
case '_':
default:
// variable name should match [A-Za-z0-9_.]
if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || rchar == '.' {
// variable name should match [A-Za-z0-9_.-]
if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) || rchar == '.' || rchar == '-' {
continue
}