Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accept dashes in variable names #336

Merged
merged 1 commit into from Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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