Skip to content

Commit

Permalink
allow '.' (dot) in environment variable name
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
  • Loading branch information
glours committed Jun 7, 2022
1 parent e497f1b commit 5f3fae0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dotenv/parser.go
Expand Up @@ -105,9 +105,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
2 changes: 2 additions & 0 deletions loader/example1.env
@@ -1,5 +1,7 @@
# passed through
FOO=foo_from_env_file
ENV.WITH.DOT=ok
ENV_WITH_UNDERSCORE=ok

# overridden in example2.env
BAR=bar_from_env_file
Expand Down
14 changes: 10 additions & 4 deletions loader/full-struct_test.go
Expand Up @@ -164,10 +164,12 @@ func services(workingDir, homeDir string) []types.ServiceConfig {
DomainName: "foo.com",
Entrypoint: []string{"/code/entrypoint.sh", "-p", "3000"},
Environment: map[string]*string{
"FOO": strPtr("foo_from_env_file"),
"BAR": strPtr("this is a secret"),
"BAZ": strPtr("baz_from_service_def"),
"QUX": strPtr("qux_from_environment"),
"FOO": strPtr("foo_from_env_file"),
"BAR": strPtr("this is a secret"),
"BAZ": strPtr("baz_from_service_def"),
"QUX": strPtr("qux_from_environment"),
"ENV.WITH.DOT": strPtr("ok"),
"ENV_WITH_UNDERSCORE": strPtr("ok"),
},
EnvFile: []string{
"./example1.env",
Expand Down Expand Up @@ -691,6 +693,8 @@ services:
environment:
BAR: this is a secret
BAZ: baz_from_service_def
ENV.WITH.DOT: ok
ENV_WITH_UNDERSCORE: ok
FOO: foo_from_env_file
QUX: qux_from_environment
env_file:
Expand Down Expand Up @@ -1261,6 +1265,8 @@ func fullExampleJSON(workingDir, homeDir string) string {
"environment": {
"BAR": "this is a secret",
"BAZ": "baz_from_service_def",
"ENV.WITH.DOT": "ok",
"ENV_WITH_UNDERSCORE": "ok",
"FOO": "foo_from_env_file",
"QUX": "qux_from_environment"
},
Expand Down
10 changes: 6 additions & 4 deletions loader/loader_test.go
Expand Up @@ -766,10 +766,12 @@ func TestDiscardEnvFileOption(t *testing.T) {
- example2.env
`
expectedEnvironmentMap := types.MappingWithEquals{
"FOO": strPtr("foo_from_env_file"),
"BAZ": strPtr("baz_from_env_file"),
"BAR": strPtr("bar_from_env_file_2"), // Original value is overwritten by example2.env
"QUX": strPtr("quz_from_env_file_2"),
"FOO": strPtr("foo_from_env_file"),
"BAZ": strPtr("baz_from_env_file"),
"BAR": strPtr("bar_from_env_file_2"), // Original value is overwritten by example2.env
"QUX": strPtr("quz_from_env_file_2"),
"ENV.WITH.DOT": strPtr("ok"),
"ENV_WITH_UNDERSCORE": strPtr("ok"),
}
configDetails := buildConfigDetails(dict, nil)

Expand Down

0 comments on commit 5f3fae0

Please sign in to comment.