Skip to content

Commit 2fb9d06

Browse files
committed
Allow environment variables to start with underscores
1 parent bbaf784 commit 2fb9d06

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

envconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ func validateEnvName(s string) bool {
856856
}
857857

858858
for i, r := range s {
859-
if (i == 0 && !isLetter(r)) || (!isLetter(r) && !isNumber(r) && r != '_') {
859+
if (i == 0 && !isLetter(r) && r != '_') || (!isLetter(r) && !isNumber(r) && r != '_') {
860860
return false
861861
}
862862
}

envconfig_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,11 @@ func TestValidateEnvName(t *testing.T) {
30713071
in: "FOO",
30723072
exp: true,
30733073
},
3074+
{
3075+
name: "underscore_start",
3076+
in: "_foo",
3077+
exp: true,
3078+
},
30743079
{
30753080
name: "emoji_middle",
30763081
in: "FOO🚀",

0 commit comments

Comments
 (0)