diff --git a/etc/schemas/arduino-library-properties-definitions-schema.json b/etc/schemas/arduino-library-properties-definitions-schema.json index acb39870..c9d8b938 100644 --- a/etc/schemas/arduino-library-properties-definitions-schema.json +++ b/etc/schemas/arduino-library-properties-definitions-schema.json @@ -413,6 +413,9 @@ "allOf": [ { "type": "string" + }, + { + "minLength": 1 } ] } diff --git a/internal/rule/ruleconfiguration/ruleconfiguration.go b/internal/rule/ruleconfiguration/ruleconfiguration.go index 660329ae..414da657 100644 --- a/internal/rule/ruleconfiguration/ruleconfiguration.go +++ b/internal/rule/ruleconfiguration/ruleconfiguration.go @@ -889,6 +889,22 @@ var configurations = []Type{ ErrorModes: []rulemode.Type{rulemode.Default}, RuleFunction: rulefunction.LibraryPropertiesUrlFieldMissing, }, + { + ProjectType: projecttype.Library, + SuperprojectType: projecttype.All, + Category: "library.properties", + Subcategory: "url field", + ID: "LP056", + Brief: "url < min length", + Description: "", + MessageTemplate: "library.properties url value is less than minimum length.", + DisableModes: nil, + EnableModes: []rulemode.Type{rulemode.Default}, + InfoModes: nil, + WarningModes: nil, + ErrorModes: []rulemode.Type{rulemode.Default}, + RuleFunction: rulefunction.LibraryPropertiesUrlFieldLTMinLength, + }, { ProjectType: projecttype.Library, SuperprojectType: projecttype.All, diff --git a/internal/rule/rulefunction/library.go b/internal/rule/rulefunction/library.go index 663721da..db72dd8d 100644 --- a/internal/rule/rulefunction/library.go +++ b/internal/rule/rulefunction/library.go @@ -944,6 +944,23 @@ func LibraryPropertiesUrlFieldMissing() (result ruleresult.Type, output string) return ruleresult.Pass, "" } +// LibraryPropertiesUrlFieldLTMinLength checks if the library.properties "url" value is less than the minimum length. +func LibraryPropertiesUrlFieldLTMinLength() (result ruleresult.Type, output string) { + if projectdata.LibraryPropertiesLoadError() != nil { + return ruleresult.NotRun, "Couldn't load library.properties" + } + + if !projectdata.LibraryProperties().ContainsKey("url") { + return ruleresult.NotRun, "Field not present" + } + + if schema.PropertyLessThanMinLength("url", projectdata.LibraryPropertiesSchemaValidationResult()[compliancelevel.Permissive]) { + return ruleresult.Fail, "" + } + + return ruleresult.Pass, "" +} + // LibraryPropertiesUrlFieldInvalid checks whether the library.properties "url" value has a valid URL format. func LibraryPropertiesUrlFieldInvalid() (result ruleresult.Type, output string) { if projectdata.LibraryPropertiesLoadError() != nil { diff --git a/internal/rule/rulefunction/library_test.go b/internal/rule/rulefunction/library_test.go index f39b5d31..fb2f2a3d 100644 --- a/internal/rule/rulefunction/library_test.go +++ b/internal/rule/rulefunction/library_test.go @@ -714,6 +714,17 @@ func TestLibraryPropertiesUrlFieldMissing(t *testing.T) { checkLibraryRuleFunction(LibraryPropertiesUrlFieldMissing, testTables, t) } +func TestLibraryPropertiesUrlFieldLTMinLength(t *testing.T) { + testTables := []libraryRuleFunctionTestTable{ + {"Invalid", "InvalidLibraryProperties", ruleresult.NotRun, ""}, + {"Legacy", "Legacy", ruleresult.NotRun, ""}, + {"url field too short", "UrlLTMinLength", ruleresult.Fail, ""}, + {"Valid", "Recursive", ruleresult.Pass, ""}, + } + + checkLibraryRuleFunction(LibraryPropertiesUrlFieldLTMinLength, testTables, t) +} + func TestLibraryPropertiesUrlFieldInvalid(t *testing.T) { testTables := []libraryRuleFunctionTestTable{ {"Invalid", "InvalidLibraryProperties", ruleresult.NotRun, ""}, diff --git a/internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/library.properties b/internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/library.properties new file mode 100644 index 00000000..d4613990 --- /dev/null +++ b/internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/library.properties @@ -0,0 +1,10 @@ +name=UrlLTMinLength +version=1.0.0 +author=Cristian Maglie , Pippo Pluto +maintainer=Cristian Maglie +sentence=A library that makes coding a web server a breeze. +paragraph=Supports HTTP1.1 and you can do GET and POST. +category=Communication +url= +architectures=avr +includes=UrlLTMinLength.h diff --git a/internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/src/UrlLTMinLength.h b/internal/rule/rulefunction/testdata/libraries/UrlLTMinLength/src/UrlLTMinLength.h new file mode 100644 index 00000000..e69de29b diff --git a/internal/rule/schema/schemadata/bindata.go b/internal/rule/schema/schemadata/bindata.go index 43eeb5da..16cc58ce 100644 --- a/internal/rule/schema/schemadata/bindata.go +++ b/internal/rule/schema/schemadata/bindata.go @@ -1832,6 +1832,9 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{ "allOf": [ { "type": "string" + }, + { + "minLength": 1 } ] }