Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
3 changes: 2 additions & 1 deletion pkg/manifest/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
Loading