Skip to content

Commit

Permalink
Reapply "accept dashes in variable names"
Browse files Browse the repository at this point in the history
This reverts commit aa1db26.

Signed-off-by: Nicolas De Loof <[email protected]>
  • Loading branch information
ndeloof committed Sep 17, 2024
1 parent 992d46e commit f038655
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions dotenv/fixtures/special.env
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,14 @@ 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)
}

func TestGetEnvFromFile(t *testing.T) {
wd := t.TempDir()
f := filepath.Join(wd, ".env")
Expand Down
2 changes: 1 addition & 1 deletion dotenv/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ loop:
offset = i + 1
inherited = rune == '\n'
break loop
case '_', '.', '[', ']':
case '_', '.', '-', '[', ']':
default:
// variable name should match [A-Za-z0-9_.-]
if unicode.IsLetter(rune) || unicode.IsNumber(rune) {
Expand Down
10 changes: 5 additions & 5 deletions dotenv/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ var testInput = `
a=b
a[1]=c
a.propertyKey=d
árvíztűrőTÜKÖRFÚRÓGÉP=ÁRVÍZTŰRŐtükörfúrógép
árvíztűrő-TÜKÖRFÚRÓGÉP=ÁRVÍZTŰRŐ-tükörfúrógép
`

func TestParseBytes(t *testing.T) {
p := newParser()

expectedOutput := map[string]string{
"a": "b",
"a[1]": "c",
"a.propertyKey": "d",
"árvíztűrőTÜKÖRFÚRÓGÉP": "ÁRVÍZTŰRŐtükörfúrógép",
"a": "b",
"a[1]": "c",
"a.propertyKey": "d",
"árvíztűrő-TÜKÖRFÚRÓGÉP": "ÁRVÍZTŰRŐ-tükörfúrógép",
}

out := map[string]string{}
Expand Down

0 comments on commit f038655

Please sign in to comment.