Skip to content
Open
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
2 changes: 1 addition & 1 deletion api/internal/accumulator/loadconfigfromcrds.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func LoadConfigFromCRDs(
}

func makeNameToApiMap(content []byte) (result nameToApiMap, err error) {
if content[0] == '{' {
if len(content) > 0 && content[0] == '{' {
err = json.Unmarshal(content, &result)
} else {
err = yaml.Unmarshal(content, &result)
Expand Down
14 changes: 14 additions & 0 deletions api/internal/accumulator/loadconfigfromcrds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,17 @@ func TestLoadCRDs(t *testing.T) {
t.Fatalf("expected\n %v\n but got\n %v\n", expectedTc, actualTc)
}
}

func TestLoadCRDsEmptyFile(t *testing.T) {
// A crds entry pointing at a zero-byte file should contribute nothing
// rather than crashing the build.
fSys := filesys.MakeFsInMemory()
err := fSys.WriteFile("/testpath/empty.json", []byte(""))
require.NoError(t, err)
ldr, err := loader.NewLoader(loader.RestrictionRootOnly, "/testpath", fSys)
require.NoError(t, err)

actualTc, err := LoadConfigFromCRDs(ldr, []string{"empty.json"})
require.NoError(t, err)
require.Equal(t, &builtinconfig.TransformerConfig{}, actualTc)
}
Loading