Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Remove outdated constraint validation from depends field pattern in l…
…ibrary.properties schema

A regular expression is employed in the library.properties JSON schemas to validate the format of the contents of the
depends field. Previously, this regular expression was configured to validate the syntax of the optional version
constraint.

The constraint system has recently been made much more capable through the addition of support for more syntax. The
regular expression did not have support for that syntax, which caused valid data to fail validation.

Expanding the already complex and lengthy regular expression to comprehensively validate the full range of constraint
forms possible
with the new syntax would not be feasible or maintainable.

The new approach is to validate it directly via Go code using the same `go.bug.st/relaxed-semver` module used by
Arduino CLI and `arduino/libraries-repository-engine` to handle the version constraints in this field. The schema will
continue to provide a general validation on the `depends` field format.
  • Loading branch information
per1234 committed May 26, 2022
commit 264f66accbdb0e808dafe68aa44ca62591838f4c
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@
"type": "string"
},
{
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters and general-definitions-schema.json#/definitions/patternObjects/relaxedSemver",
"pattern": "^((((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\( *(<|<=|=|>=|>)(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))?(\\.(0|[1-9]\\d*))?(-((0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))? *\\) *)?), *)*((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\( *(<|<=|=|>=|>)(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))?(\\.(0|[1-9]\\d*))?(-((0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))? *\\) *)?))?$"
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters",
"pattern": "^((((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\(.*\\) *)?), *)*((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\(.*\\) *)?))?$"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,21 @@ func TestPropertiesDependsPattern(t *testing.T) {
{"Pre-release version", "foo (=1.2.3-rc1)", compliancelevel.Specification, assert.False},
{"Pre-release version", "foo (=1.2.3-rc1)", compliancelevel.Strict, assert.False},

{"Invalid version", "foo (bar)", compliancelevel.Permissive, assert.True},
{"Invalid version", "foo (bar)", compliancelevel.Specification, assert.True},
{"Invalid version", "foo (bar)", compliancelevel.Strict, assert.True},

{"Version w/o space", "foo(>1.2.3)", compliancelevel.Permissive, assert.True},
{"Version w/o space", "foo(>1.2.3)", compliancelevel.Specification, assert.True},
{"Version w/o space", "foo(>1.2.3)", compliancelevel.Strict, assert.True},

{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Permissive, assert.False},
{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Specification, assert.False},
{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Strict, assert.False},

{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Permissive, assert.False},
{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Specification, assert.False},
{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Strict, assert.False},

{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Permissive, assert.False},
{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Specification, assert.False},
{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Strict, assert.False},
}

checkPropertyPatternMismatch("depends", testTables, t)
Expand Down
4 changes: 2 additions & 2 deletions internal/rule/schema/schemadata/bindata.go
Original file line number Diff line number Diff line change
Expand Up @@ -1911,8 +1911,8 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
"type": "string"
},
{
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters and general-definitions-schema.json#/definitions/patternObjects/relaxedSemver",
"pattern": "^((((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\( *(<|<=|=|>=|>)(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))?(\\.(0|[1-9]\\d*))?(-((0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))? *\\) *)?), *)*((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\( *(<|<=|=|>=|>)(0|[1-9]\\d*)(\\.(0|[1-9]\\d*))?(\\.(0|[1-9]\\d*))?(-((0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))? *\\) *)?))?$"
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters",
"pattern": "^((((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\(.*\\) *)?), *)*((([a-zA-Z][a-zA-Z0-9 _.\\-]*)|([0-9][a-zA-Z0-9 _.\\-]*[a-zA-Z][a-zA-Z0-9 _.\\-]*))+( \\(.*\\) *)?))?$"
}
]
}
Expand Down