Skip to content
Draft
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
29 changes: 0 additions & 29 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,35 +318,6 @@ func validateFieldsV1(publiccode PublicCode, parser *Parser, network bool, baseU
}
}

if publiccodev1.IntendedAudience != nil {
// This is not ideal, but we need to revalidate the countries
// here, because otherwise we could get a warning and the advice
// to use uppercase on an invalid country.
if publiccodev1.IntendedAudience.Countries != nil {
for i, c := range *publiccodev1.IntendedAudience.Countries {
if sharedValidate.Var(c, "iso3166_1_alpha2_lower_or_upper") == nil && c == strings.ToLower(c) {
vr = append(vr, ValidationWarning{
fmt.Sprintf("intendedAudience.countries[%d]", i),
fmt.Sprintf("Lowercase country codes are DEPRECATED. Use uppercase instead ('%s')", strings.ToUpper(c)),
0, 0,
})
}
}
}

if publiccodev1.IntendedAudience.UnsupportedCountries != nil {
for i, c := range *publiccodev1.IntendedAudience.UnsupportedCountries {
if sharedValidate.Var(c, "iso3166_1_alpha2_lower_or_upper") == nil && c == strings.ToLower(c) {
vr = append(vr, ValidationWarning{
fmt.Sprintf("intendedAudience.unsupportedCountries[%d]", i),
fmt.Sprintf("Lowercase country codes are DEPRECATED. Use uppercase instead ('%s')", strings.ToUpper(c)),
0, 0,
})
}
}
}
}

for lang, desc := range publiccodev1.Description {
if checksNetwork && desc.Documentation != nil {
if reachable, err := parser.isReachable(*(*url.URL)(desc.Documentation)); !reachable {
Expand Down
31 changes: 0 additions & 31 deletions fields_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,37 +261,6 @@ func TestValidateFieldsV1WithAPIDocNetworkCheck(t *testing.T) {
}
}

func TestValidateFieldsV1WithCountriesDeprecated(t *testing.T) {
p, _ := NewParser(ParserConfig{DisableNetwork: true, DisableExternalChecks: true})
base := &url.URL{Scheme: "file", Path: "/tmp"}

countries := []string{"it"} // lowercase - deprecated
unsupported := []string{"de"} // lowercase - deprecated
locReady := true
v1 := &PublicCodeV1{
IntendedAudience: &struct {
Scope *[]string `json:"scope,omitempty" validate:"omitempty,dive,is_scope_v0" yaml:"scope,omitempty"`
Countries *[]string `json:"countries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lower_or_upper" yaml:"countries,omitempty"`
UnsupportedCountries *[]string `json:"unsupportedCountries,omitempty" validate:"omitempty,dive,iso3166_1_alpha2_lower_or_upper" yaml:"unsupportedCountries,omitempty"`
}{
Countries: &countries,
UnsupportedCountries: &unsupported,
},
Localisation: struct {
LocalisationReady *bool `json:"localisationReady" validate:"required" yaml:"localisationReady"`
AvailableLanguages []string `json:"availableLanguages" validate:"required,gt=0,dive,bcp47_strict_language_tag" yaml:"availableLanguages"`
}{
LocalisationReady: &locReady,
AvailableLanguages: []string{"en"},
},
}

err := validateFieldsV1(v1, p, false, base)
if err == nil {
t.Error("expected deprecation warnings for lowercase countries")
}
}

func TestValidateFieldsV0MonochromeLogoAbsPath(t *testing.T) {
p, _ := NewParser(ParserConfig{DisableNetwork: true, DisableExternalChecks: false})
base := &url.URL{Scheme: "file", Path: "/tmp"}
Expand Down
6 changes: 2 additions & 4 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,14 @@ func (p *Parser) parseStream(in io.Reader, fileURL *url.URL) (PublicCode, error)

var ve ValidationResults

if slices.Contains(SupportedVersions, version) && version != "0" && !strings.HasPrefix(version, "0.5") {
latestVersion := SupportedVersions[len(SupportedVersions)-1]
if version != "0" && version != "1" && !strings.HasPrefix(version, "0.5") {
line, column := getPositionInFile("publiccodeYmlVersion", file)

ve = append(ve, ValidationWarning{
Key: "publiccodeYmlVersion",
Description: fmt.Sprintf(
"v%s is not the latest version, use '0'. Parsing this file as v%s.",
"v%s is not the latest version, use '0'. Parsing this file as v0.5.",
version,
latestVersion,
),
Line: line,
Column: column,
Expand Down
9 changes: 8 additions & 1 deletion publiccode.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package publiccode

// SupportedVersions lists the publiccode.yml versions this parser supports.
var SupportedVersions = []string{"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"}
var SupportedVersions = []string{
"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",
"1",
}

type PublicCode interface {
Version() uint
Expand Down
4 changes: 2 additions & 2 deletions testdata/v0/invalid/publiccodeYmlVersion_invalid.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Should NOT validate: version 1 doesn't exist yet
publiccodeYmlVersion: "1"
# Should NOT validate: version 2 doesn't exist yet
publiccodeYmlVersion: "2"

name: Medusa
url: "https://github.com/italia/developers.italia.it.git"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand All @@ -114,6 +114,7 @@ dependsOn:
- name: NFC Reader
optional: true

# Should NOT validate: the IT section was removed in v1
IT:
riuso:
codiceIPA: pcm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dependsOn:
- name: NFC Reader2
optional: true

# Should have a warning here, downcase is deprecated:
# Should NOT validate: the it section was removed in v1
it:
countryExtensionVersion: "1.0"

Expand Down
38 changes: 38 additions & 0 deletions testdata/v1/invalid/intendedAudience_scope_government.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
publiccodeYmlVersion: "1"

name: TestSoftware
url: "https://github.com/italia/developers.italia.it.git"

platforms:
- web

developmentStatus: stable

softwareType: "standalone/web"

intendedAudience:
scope:
# Should NOT validate: government was removed from the scope list in v1
- government

description:
en:
shortDescription: "A test software for v1 parsing."
longDescription: >
This is a long description for the test software used to verify
that the v1 parser works correctly. It needs to be at least 150
characters long to pass validation checks in the publiccode.yml
parser implementation. This is enough text now.
features:
- Test feature

legal:
license: MIT

maintenance:
type: none

localisation:
localisationReady: true
availableLanguages:
- en
123 changes: 0 additions & 123 deletions testdata/v1/invalid/it_IT_duplicated.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand All @@ -114,8 +114,8 @@ dependsOn:
- name: NFC Reader
optional: true

# Should NOT validate: the IT section was removed in v1
IT:
# Should have warnings for IT.conforme, because it is deprecated
conforme:
lineeGuidaDesign: true
modelloInteroperabilita: true
Expand Down
6 changes: 3 additions & 3 deletions testdata/v1/invalid/landingURL_invalid.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand Down
6 changes: 3 additions & 3 deletions testdata/v1/invalid/landingURL_wrong_type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,15 @@ maintenance:
- name: Francesco Rossi
email: "francesco.rossi@comune.reggioemilia.it"
affiliation: Comune di Reggio Emilia
phone: +39 231 13215112
phone: +3923113215112
- name: Dario Bianchi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322
- name: Giancarlo Verdi
email: "dario.bianchi@fornitore.it"
affiliation: Fornitore Privato S.P.A.
phone: +39 16 24231322
phone: +391624231322

localisation:
localisationReady: true
Expand Down
Loading
Loading