Skip to content

Commit be170be

Browse files
committed
accept dashes in variable names
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent 7d49c99 commit be170be

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

dotenv/fixtures/special.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
VAR.WITH.DOTS=dots
2+
VAR_WITH_UNDERSCORES=underscores
3+
VAR-WITH-DASHES=dashes

dotenv/godotenv_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,3 +718,11 @@ func TestUTF8BOM(t *testing.T) {
718718

719719
loadEnvAndCompareValues(t, Load, envFileName, expectedValues, noopPresets)
720720
}
721+
722+
func TestDash(t *testing.T) {
723+
loadEnvAndCompareValues(t, Load, "fixtures/special.env", map[string]string{
724+
"VAR-WITH-DASHES": "dashes",
725+
"VAR.WITH.DOTS": "dots",
726+
"VAR_WITH_UNDERSCORES": "underscores",
727+
}, noopPresets)
728+
}

dotenv/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ loop:
108108
offset = i + 1
109109
inherited = char == '\n'
110110
break loop
111-
case '_', '.':
111+
case '_', '.', '-':
112112
default:
113-
// variable name should match [A-Za-z0-9_.]
113+
// variable name should match [A-Za-z0-9_.-]
114114
if unicode.IsLetter(rchar) || unicode.IsNumber(rchar) {
115115
continue
116116
}

0 commit comments

Comments
 (0)