From 73db2e7a1538ff588c63f104b90d4470e0f58598 Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Fri, 6 Nov 2026 06:24:15 +0100 Subject: [PATCH] fix: don't panic on a null item in videos --- fields.go | 8 ++++++++ testdata/v0/invalid/description_en_videos_invalid.yml | 4 ++++ testdata/v1/invalid/description_en_videos_invalid.yml | 4 ++++ v0.go | 2 +- v0_test.go | 3 +++ v1.go | 2 +- 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/fields.go b/fields.go index f9f180e..325511b 100644 --- a/fields.go +++ b/fields.go @@ -257,6 +257,10 @@ func validateFieldsV0(publiccode PublicCode, parser *Parser, network bool, baseU } for i, v := range desc.Videos { + if v == nil { + continue + } + err := parser.checkOEmbedURL((*url.URL)(v)) if err != nil { vr = append(vr, newValidationErrorf( @@ -431,6 +435,10 @@ func validateFieldsV1(publiccode PublicCode, parser *Parser, network bool, baseU } for i, v := range desc.Videos { + if v == nil { + continue + } + err := parser.checkOEmbedURL((*url.URL)(v)) if err != nil { vr = append(vr, newValidationErrorf( diff --git a/testdata/v0/invalid/description_en_videos_invalid.yml b/testdata/v0/invalid/description_en_videos_invalid.yml index e0b8608..5c04ef4 100644 --- a/testdata/v0/invalid/description_en_videos_invalid.yml +++ b/testdata/v0/invalid/description_en_videos_invalid.yml @@ -39,6 +39,10 @@ description: videos: # Should NOT validate: not a valid URL - ABC + # Should NOT validate: null is not a URL + - + # Should NOT validate: an empty string is not a URL + - "" legal: license: AGPL-3.0-or-later diff --git a/testdata/v1/invalid/description_en_videos_invalid.yml b/testdata/v1/invalid/description_en_videos_invalid.yml index 53ca1a8..d8f4fee 100644 --- a/testdata/v1/invalid/description_en_videos_invalid.yml +++ b/testdata/v1/invalid/description_en_videos_invalid.yml @@ -39,6 +39,10 @@ description: videos: # Should NOT validate: not a valid URL - ABC + # Should NOT validate: null is not a URL + - + # Should NOT validate: an empty string is not a URL + - "" legal: license: AGPL-3.0-or-later diff --git a/v0.go b/v0.go index af40fa5..07d9203 100644 --- a/v0.go +++ b/v0.go @@ -92,7 +92,7 @@ type DescV0 struct { APIDocumentation *URL `json:"apiDocumentation,omitempty" validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"` Features *[]string `json:"features,omitempty" validate:"gt=0,dive" yaml:"features,omitempty"` Screenshots []string `json:"screenshots,omitempty" yaml:"screenshots,omitempty"` - Videos []*URL `json:"videos,omitempty" validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"` + Videos []*URL `json:"videos,omitempty" validate:"dive,required,url_http_url" yaml:"videos,omitempty"` Awards []string `json:"awards,omitempty" yaml:"awards,omitempty"` } diff --git a/v0_test.go b/v0_test.go index 6de8e0f..76b0689 100644 --- a/v0_test.go +++ b/v0_test.go @@ -445,8 +445,11 @@ func TestInvalidTestcasesV0(t *testing.T) { }, "description_en_videos_invalid.yml": ValidationResults{ ValidationError{"", "description.en.videos[0]", "videos[0] must be an HTTP URL", 41, 9}, + ValidationError{"", "description.en.videos[1]", "videos[1] is a required field", 43, 8}, + ValidationError{"", "description.en.videos[2]", "videos[2] must be an HTTP URL", 45, 9}, 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}, ValidationError{"", "description.en.videos[0]", "'ABC' is not a valid video URL supporting oEmbed: invalid oEmbed link: ABC", 41, 9}, + ValidationError{"", "description.en.videos[2]", "'' is not a valid video URL supporting oEmbed: invalid oEmbed link: ", 45, 9}, }, "description_en_videos_invalid_oembed.yml": ValidationResults{ 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}, diff --git a/v1.go b/v1.go index dd76c86..af6b58f 100644 --- a/v1.go +++ b/v1.go @@ -77,7 +77,7 @@ type DescV1 struct { APIDocumentation *URL `json:"apiDocumentation,omitempty" validate:"omitnil,url_http_url" yaml:"apiDocumentation,omitempty"` Features *[]string `json:"features,omitempty" validate:"gt=0,dive" yaml:"features,omitempty"` Screenshots []string `json:"screenshots,omitempty" yaml:"screenshots,omitempty"` - Videos []*URL `json:"videos,omitempty" validate:"dive,omitnil,url_http_url" yaml:"videos,omitempty"` + Videos []*URL `json:"videos,omitempty" validate:"dive,required,url_http_url" yaml:"videos,omitempty"` Awards []string `json:"awards,omitempty" yaml:"awards,omitempty"` }