diff --git a/CHANGELOG.md b/CHANGELOG.md index 66194f1a8..67ff8f215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### Bug Fixes: - fix(vcl/condition): `--comment` flag in `condition update` now correctly sets the comment instead of overwriting the statement +- fix(manifest): `env_file` parsing no longer rejects values containing `=` characters (e.g. `KEY=val=ue`). ### Enhancements: diff --git a/pkg/manifest/file.go b/pkg/manifest/file.go index d430c152c..c0804f7cc 100644 --- a/pkg/manifest/file.go +++ b/pkg/manifest/file.go @@ -264,9 +264,10 @@ func (f *File) ParseEnvFile() error { if err != nil { return fmt.Errorf("failed to open path '%s': %w", path, err) } + defer r.Close() scanner := bufio.NewScanner(r) for scanner.Scan() { - parts := strings.Split(scanner.Text(), "=") + parts := strings.SplitN(scanner.Text(), "=", 2) if len(parts) != 2 { return fmt.Errorf("failed to scan env_file '%s': invalid KEY=VALUE format: %#v", path, parts) } diff --git a/pkg/manifest/manifest_test.go b/pkg/manifest/manifest_test.go index 09f775e15..83bdc9cea 100644 --- a/pkg/manifest/manifest_test.go +++ b/pkg/manifest/manifest_test.go @@ -308,3 +308,55 @@ func TestManifestPersistsLocalServerSection(t *testing.T) { t.Fatalf("testing section between original and updated fastly.toml do not match (-want +got):\n%s", diff) } } + +func TestParseEnvFile(t *testing.T) { + tests := map[string]struct { + content string + wantVars []string + wantErr bool + }{ + "simple key=value": { + content: "FOO=bar\n", + wantVars: []string{"FOO=bar"}, + }, + "value contains equals sign": { + content: "SECRET=dGVzdA==\n", + wantVars: []string{"SECRET=dGVzdA=="}, + }, + "multiple entries with equals in values": { + content: "A=1\nB=x=y=z\n", + wantVars: []string{"A=1", "B=x=y=z"}, + }, + "invalid line without equals": { + content: "BADLINE\n", + wantErr: true, + }, + } + + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + tmp := t.TempDir() + envPath := filepath.Join(tmp, ".env") + if err := os.WriteFile(envPath, []byte(tc.content), 0o600); err != nil { + t.Fatal(err) + } + + f := &manifest.File{} + f.Scripts.EnvFile = envPath + + err := f.ParseEnvFile() + if tc.wantErr { + if err == nil { + t.Fatal("expected error, got nil") + } + return + } + if err != nil { + t.Fatalf("unexpected error: %v", err) + } + if diff := cmp.Diff(tc.wantVars, f.Scripts.EnvVars); diff != "" { + t.Fatalf("EnvVars mismatch (-want +got):\n%s", diff) + } + }) + } +}