Skip to content

Commit be8c7b7

Browse files
fix: julia parser panicing (#8883)
Co-authored-by: DmitriyLewen <[email protected]>
1 parent 6aff7b0 commit be8c7b7

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

pkg/dependency/parser/julia/manifest/parse.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ func decodeDependency(man *primitiveManifest, dep primitiveDependency, metadata
140140
var possibleUuids []string
141141
for _, depName := range possibleDeps {
142142
primDep := man.Dependencies[depName]
143+
if len(primDep) == 0 {
144+
return primitiveDependency{}, xerrors.Errorf("Dependency %q has invalid format (parsed no deps): %s", depName, primDep)
145+
}
143146
if len(primDep) > 1 {
144147
return primitiveDependency{}, xerrors.Errorf("Dependency %q has invalid format (parsed multiple deps): %s", depName, primDep)
145148
}

pkg/dependency/parser/julia/manifest/parse_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestParse(t *testing.T) {
1717
file string // Test input file
1818
want []ftypes.Package
1919
wantDeps []ftypes.Dependency
20+
wantErr string
2021
}{
2122
{
2223
name: "Manifest v1.6",
@@ -60,6 +61,16 @@ func TestParse(t *testing.T) {
6061
want: juliaV10FormatPkgs,
6162
wantDeps: juliaV10FormatDeps,
6263
},
64+
{
65+
name: "Manifest file doesn't contain child dependency of another dependency",
66+
file: "testdata/missed-child-dep/Manifest.toml",
67+
wantErr: "has invalid format (parsed no deps)",
68+
},
69+
{
70+
name: "Manifest file contains multiple dependencies with same name",
71+
file: "testdata/multiple-same-deps/Manifest.toml",
72+
wantErr: "has invalid format (parsed multiple deps)",
73+
},
6374
}
6475

6576
for _, tt := range tests {
@@ -68,6 +79,11 @@ func TestParse(t *testing.T) {
6879
require.NoError(t, err)
6980

7081
gotPkgs, gotDeps, err := NewParser().Parse(f)
82+
83+
if tt.wantErr != "" {
84+
require.ErrorContains(t, err, tt.wantErr)
85+
return
86+
}
7187
require.NoError(t, err)
7288

7389
sort.Sort(ftypes.Packages(tt.want))
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[Base64]]
4+
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
5+
6+
[[Dates]]
7+
deps = ["Printf"]
8+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
9+
10+
[[InteractiveUtils]]
11+
deps = ["Markdown"]
12+
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
13+
14+
[[LibGit2]]
15+
deps = ["Printf"]
16+
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# This file is machine-generated - editing it directly is not advised
2+
3+
[[Dates]]
4+
deps = ["Printf"]
5+
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
6+
7+
[[Printf]]
8+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
9+
10+
[[Printf]]
11+
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d8"

0 commit comments

Comments
 (0)