Skip to content

Commit

Permalink
Merge pull request #4 from jtatarik/env-variable-prefix
Browse files Browse the repository at this point in the history
fix(validation): allow environment variable names with leading underscore
  • Loading branch information
valentindeaconu authored Dec 16, 2024
2 parents fc6d0c9 + 29a71e5 commit 31cfe1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions circleci/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

var (
// https://circleci.com/docs/2.0/env-vars/#injecting-environment-variables-with-the-api
environmentVariablePrefixRegex = regexp.MustCompile("^[[:alpha:]]")
environmentVariablePrefixRegex = regexp.MustCompile("^[[:alpha:]_]")
environmentVariableCharsRegex = regexp.MustCompile("^[[:word:]]+$")
)

Expand All @@ -19,7 +19,7 @@ func validateEnvironmentVariableNameFunc(v interface{}, key string) (warns []str
}

if !environmentVariablePrefixRegex.MatchString(name) {
errs = append(errs, errors.New("environment variables may only begin with a letter"))
errs = append(errs, errors.New("environment variables may only begin with a letter or an underscore"))
}

if !environmentVariableCharsRegex.MatchString(name) {
Expand Down
7 changes: 3 additions & 4 deletions circleci/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ func TestValidateEnvironmentVariableName(t *testing.T) {
{
Name: "VALID_UNDERSCORE_",
},
{
Name: "_VALID_LEADING_UNDERSCORE",
},
{
Name: "VALID_DIGIT_1",
},
Expand All @@ -27,10 +30,6 @@ func TestValidateEnvironmentVariableName(t *testing.T) {
Name: "1_invalid_leading_digit",
Error: true,
},
{
Name: "_invalid_leading_underscore",
Error: true,
},
}

for _, tc := range cases {
Expand Down

0 comments on commit 31cfe1b

Please sign in to comment.