From 88a318b4db397dc85046243ccc26916d6ff94345 Mon Sep 17 00:00:00 2001 From: Fabio Bonelli Date: Sat, 14 Nov 2026 20:36:56 +0000 Subject: [PATCH] fix: accept publiccode.yml 0.6 --- parser_extra_test.go | 29 +++++++++++++++++++++++++++++ publiccode.go | 1 + v0.go | 2 +- v0_test.go | 2 +- v1_test.go | 2 +- 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/parser_extra_test.go b/parser_extra_test.go index 5e23da7..c5c3cc9 100644 --- a/parser_extra_test.go +++ b/parser_extra_test.go @@ -6,6 +6,7 @@ import ( "net/http" "net/http/httptest" "os" + "reflect" "strings" "testing" ) @@ -262,3 +263,31 @@ localisation: } } + +func TestParseStreamVersion06(t *testing.T) { + data, err := os.ReadFile("testdata/v0/valid/no-network/standard_minimal_example.yml") + if err != nil { + t.Fatal(err) + } + + for _, version := range []string{"0.6", "0.6.0"} { + t.Run(version, func(t *testing.T) { + p, err := NewParser(ParserConfig{DisableNetwork: true}) + if err != nil { + t.Fatal(err) + } + + input := strings.Replace(string(data), `publiccodeYmlVersion: "0"`, `publiccodeYmlVersion: "`+version+`"`, 1) + pc, err := p.ParseStream(strings.NewReader(input)) + if pc == nil { + t.Fatal("expected a parsed document") + } + expected := ValidationResults{ + ValidationWarning{"", "publiccodeYmlVersion", "v" + version + " is not the latest version, use '0'. Parsing this file as v0.8.", 1, 1}, + } + if !reflect.DeepEqual(err, expected) { + t.Fatalf("unexpected diagnostics: got %#v, want %#v", err, expected) + } + }) + } +} diff --git a/publiccode.go b/publiccode.go index 7e275e4..98d4a6a 100644 --- a/publiccode.go +++ b/publiccode.go @@ -7,6 +7,7 @@ var SupportedVersions = []string{ "0.3", "0.3.0", "0.4", "0.4.0", "0.5.0", "0.5", + "0.6.0", "0.6", "0.7.0", "0.7", "0.8.0", "0.8", } diff --git a/v0.go b/v0.go index efc5f58..02c0a01 100644 --- a/v0.go +++ b/v0.go @@ -9,7 +9,7 @@ import ( // PublicCodeV0 defines how a publiccode.yml v0.x is structured. type PublicCodeV0 struct { - PubliccodeYamlVersion string `json:"publiccodeYmlVersion" validate:"required,oneof=0 0.2 0.2.0 0.2.1 0.2.2 0.3 0.3.0 0.4 0.4.0 0.5 0.5.0 0.7 0.7.0 0.8 0.8.0" yaml:"publiccodeYmlVersion"` + PubliccodeYamlVersion string `json:"publiccodeYmlVersion" validate:"required,oneof=0 0.2 0.2.0 0.2.1 0.2.2 0.3 0.3.0 0.4 0.4.0 0.5 0.5.0 0.6 0.6.0 0.7 0.7.0 0.8 0.8.0" yaml:"publiccodeYmlVersion"` Name string `json:"name" validate:"required" yaml:"name"` ApplicationSuite string `json:"applicationSuite,omitempty" yaml:"applicationSuite,omitempty"` diff --git a/v0_test.go b/v0_test.go index 8270705..e7cae25 100644 --- a/v0_test.go +++ b/v0_test.go @@ -119,7 +119,7 @@ func TestInvalidTestcasesV0(t *testing.T) { ValidationError{ "", "publiccodeYmlVersion", - "unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5, 0.7.0, 0.7, 0.8.0, 0.8", + "unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5, 0.6.0, 0.6, 0.7.0, 0.7, 0.8.0, 0.8", 0, 0, }, diff --git a/v1_test.go b/v1_test.go index e4ff115..eb44378 100644 --- a/v1_test.go +++ b/v1_test.go @@ -15,7 +15,7 @@ func TestInvalidTestcasesV1(t *testing.T) { ValidationError{ "", "publiccodeYmlVersion", - "unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5, 0.7.0, 0.7, 0.8.0, 0.8", + "unsupported version: '1'. Supported versions: 0, 0.2, 0.2.0, 0.2.1, 0.2.2, 0.3, 0.3.0, 0.4, 0.4.0, 0.5.0, 0.5, 0.6.0, 0.6, 0.7.0, 0.7, 0.8.0, 0.8", 0, 0, },