Skip to content

Commit 2d60d49

Browse files
committed
Do not define inherited environment variables that are not found via the provided lookup function. This restores the original behavior prior to docker-compose v2.
Signed-off-by: kcboschert <[email protected]>
1 parent 0621f17 commit 2d60d49

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

dotenv/godotenv_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,8 +575,8 @@ func TestInheritedEnvVariablSingleVar(t *testing.T) {
575575

576576
func TestInheritedEnvVariableNotFound(t *testing.T) {
577577
envMap, err := Read("fixtures/inherited-not-found.env")
578-
if envMap["VARIABLE_NOT_FOUND"] != "" || err != nil {
579-
t.Errorf("Expected 'VARIABLE_NOT_FOUND' to be '' with no errors")
578+
if _, ok := envMap["VARIABLE_NOT_FOUND"]; ok || err != nil {
579+
t.Errorf("Expected 'VARIABLE_NOT_FOUND' to be undefined with no errors")
580580
}
581581
}
582582

@@ -589,8 +589,8 @@ func TestInheritedEnvVariableNotFoundWithLookup(t *testing.T) {
589589
}
590590
return envVar, ok
591591
}, "fixtures/inherited-not-found.env")
592-
if envMap["VARIABLE_NOT_FOUND"] != "" || err != nil {
593-
t.Errorf("Expected 'VARIABLE_NOT_FOUND' to be '' with no errors")
592+
if _, ok := envMap["VARIABLE_NOT_FOUND"]; ok || err != nil {
593+
t.Errorf("Expected 'VARIABLE_NOT_FOUND' to be undefined with no errors")
594594
}
595595
_, ok := notFoundMap["VARIABLE_NOT_FOUND"]
596596
if !ok {

dotenv/parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func parseBytes(src []byte, out map[string]string, lookupFn LookupFn) error {
4141
value, ok := lookupFn(key)
4242
if ok {
4343
out[key] = value
44-
cutset = left
45-
continue
4644
}
45+
cutset = left
46+
continue
4747
}
4848

4949
value, left, err := extractVarValue(left, out, lookupFn)

0 commit comments

Comments
 (0)