Skip to content

Commit 264f66a

Browse files
committed
Remove outdated constraint validation from depends field pattern in library.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.
1 parent a915ba8 commit 264f66a

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

Diff for: etc/schemas/arduino-library-properties-definitions-schema.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@
493493
"type": "string"
494494
},
495495
{
496-
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters and general-definitions-schema.json#/definitions/patternObjects/relaxedSemver",
497-
"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-]+)*))? *\\) *)?))?$"
496+
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters",
497+
"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 _.\\-]*))+( \\(.*\\) *)?))?$"
498498
}
499499
]
500500
}

Diff for: internal/project/library/libraryproperties/librarypropertiesschemas_test.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,21 @@ func TestPropertiesDependsPattern(t *testing.T) {
390390
{"Pre-release version", "foo (=1.2.3-rc1)", compliancelevel.Specification, assert.False},
391391
{"Pre-release version", "foo (=1.2.3-rc1)", compliancelevel.Strict, assert.False},
392392

393-
{"Invalid version", "foo (bar)", compliancelevel.Permissive, assert.True},
394-
{"Invalid version", "foo (bar)", compliancelevel.Specification, assert.True},
395-
{"Invalid version", "foo (bar)", compliancelevel.Strict, assert.True},
396-
397393
{"Version w/o space", "foo(>1.2.3)", compliancelevel.Permissive, assert.True},
398394
{"Version w/o space", "foo(>1.2.3)", compliancelevel.Specification, assert.True},
399395
{"Version w/o space", "foo(>1.2.3)", compliancelevel.Strict, assert.True},
400396

401397
{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Permissive, assert.False},
402398
{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Specification, assert.False},
403399
{"Names w/ version", "foo (<=1.2.3),bar", compliancelevel.Strict, assert.False},
400+
401+
{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Permissive, assert.False},
402+
{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Specification, assert.False},
403+
{"Names w/ parenthesized version constraints", "foo ((>0.1.0 && <2.0.0) || >2.1.0),bar", compliancelevel.Strict, assert.False},
404+
405+
{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Permissive, assert.False},
406+
{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Specification, assert.False},
407+
{"Names w/ empty version constraint", "foo (),bar", compliancelevel.Strict, assert.False},
404408
}
405409

406410
checkPropertyPatternMismatch("depends", testTables, t)

Diff for: internal/rule/schema/schemadata/bindata.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1911,8 +1911,8 @@ var _arduinoLibraryPropertiesDefinitionsSchemaJson = []byte(`{
19111911
"type": "string"
19121912
},
19131913
{
1914-
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters and general-definitions-schema.json#/definitions/patternObjects/relaxedSemver",
1915-
"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-]+)*))? *\\) *)?))?$"
1914+
"$comment": "Based on #/definitions/propertiesObjects/name/base/definitions/patternObjects/allowedCharacters",
1915+
"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 _.\\-]*))+( \\(.*\\) *)?))?$"
19161916
}
19171917
]
19181918
}

0 commit comments

Comments
 (0)