Skip to content

Commit

Permalink
accept dashes in variable names
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Jan 3, 2023
1 parent 7d49c99 commit be170be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions dotenv/fixtures/special.env
@@ -0,0 +1,3 @@
VAR.WITH.DOTS=dots
VAR_WITH_UNDERSCORES=underscores
VAR-WITH-DASHES=dashes
8 changes: 8 additions & 0 deletions dotenv/godotenv_test.go
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions dotenv/parser.go
Expand Up @@ -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
}
Expand Down

0 comments on commit be170be

Please sign in to comment.