Skip to content

Commit 9a84238

Browse files
committed
fix: don't panic on a null item in videos
1 parent 8985d96 commit 9a84238

6 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎fields.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU
257257
}
258258

259259
for i, v := range desc.Videos {
260+
if v == nil {
261+
continue
262+
}
263+
260264
err := parser.checkOEmbedURL((*url.URL)(v))
261265
if err != nil {
262266
vr = append(vr, newValidationErrorf(
@@ -431,6 +435,10 @@ func validateFieldsV1(publiccode PublicCode, parser *Parser, network bool, baseU
431435
}
432436

433437
for i, v := range desc.Videos {
438+
if v == nil {
439+
continue
440+
}
441+
434442
err := parser.checkOEmbedURL((*url.URL)(v))
435443
if err != nil {
436444
vr = append(vr, newValidationErrorf(

‎testdata/v0/invalid/description_en_videos_invalid.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ description:
3939
videos:
4040
# Should NOT validate: not a valid URL
4141
- ABC
42+
# Should NOT validate: null is not a URL
43+
-
44+
# Should NOT validate: an empty string is not a URL
45+
- ""
4246

4347
legal:
4448
license: AGPL-3.0-or-later

‎testdata/v1/invalid/description_en_videos_invalid.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ description:
3939
videos:
4040
# Should NOT validate: not a valid URL
4141
- ABC
42+
# Should NOT validate: null is not a URL
43+
-
44+
# Should NOT validate: an empty string is not a URL
45+
- ""
4246

4347
legal:
4448
license: AGPL-3.0-or-later

‎v0.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type DescV0 struct {
9292
APIDocumentation *URL `json:"apiDocumentation,omitempty" validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"`
9393
Features *[]string `json:"features,omitempty" validate:"gt=0,dive" yaml:"features,omitempty"`
9494
Screenshots []string `json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
95-
Videos []*URL `json:"videos,omitempty" validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"`
95+
Videos []*URL `json:"videos,omitempty" validate:"dive,required,url_http_url" yaml:"videos,omitempty"`
9696
Awards []string `json:"awards,omitempty" yaml:"awards,omitempty"`
9797
}
9898

‎v0_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,11 @@ func TestInvalidTestcasesV0(t *testing.T) {
445445
},
446446
"description_en_videos_invalid.yml": ValidationResults{
447447
ValidationError{"", "description.en.videos[0]", "videos[0] must be an HTTP URL", 41, 9},
448+
ValidationError{"", "description.en.videos[1]", "videos[1] is a required field", 43, 8},
449+
ValidationError{"", "description.en.videos[2]", "videos[2] must be an HTTP URL", 45, 9},
448450
ValidationWarning{"", "description.en.videos", "This key is DEPRECATED and will be removed in the future. Link videos from the documentation or the website instead", 39, 5},
449451
ValidationError{"", "description.en.videos[0]", "'ABC' is not a valid video URL supporting oEmbed: invalid oEmbed link: ABC", 41, 9},
452+
ValidationError{"", "description.en.videos[2]", "'' is not a valid video URL supporting oEmbed: invalid oEmbed link: ", 45, 9},
450453
},
451454
"description_en_videos_invalid_oembed.yml": ValidationResults{
452455
ValidationWarning{"", "description.en.videos", "This key is DEPRECATED and will be removed in the future. Link videos from the documentation or the website instead", 39, 5},

‎v1.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type DescV1 struct {
7777
APIDocumentation *URL `json:"apiDocumentation,omitempty" validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"`
7878
Features *[]string `json:"features,omitempty" validate:"gt=0,dive" yaml:"features,omitempty"`
7979
Screenshots []string `json:"screenshots,omitempty" yaml:"screenshots,omitempty"`
80-
Videos []*URL `json:"videos,omitempty" validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"`
80+
Videos []*URL `json:"videos,omitempty" validate:"dive,required,url_http_url" yaml:"videos,omitempty"`
8181
Awards []string `json:"awards,omitempty" yaml:"awards,omitempty"`
8282
}
8383

0 commit comments

Comments
 (0)