Skip to content

Commit

Permalink
Support parentheses in depends field constraints
Browse files Browse the repository at this point in the history
Library dependencies may be specified in the `depends` field of the library.properties library metadata file.

A regular expression is used to separate the dependency name and optional version constraint from each element of the
field during parsing of the file to add new releases to the DB.

The supported version constraint syntax for use in this field was recently expanded. This included adding support for
grouping constraints using parentheses. The previous regular expression did not allow parentheses in the constraint,
which unnecessarily limited the capabilities of the library dependencies system.

The updated regular expression will match against invalid constraint syntax (e.g., `depends=FooLib (>1.2.3)(<2.3.4)`).
However, this is not a problem because the syntax is already validated separately via the dedicated tool for such things:
Arduino Lint. The DB update only occurs after the release has passed full validation by Arduino Lint.

Given the data which has already been validated by Arduino Lint, this new regular expression will reliably extract the
dependency components from the field.
  • Loading branch information
per1234 committed May 26, 2022
1 parent 1386c82 commit 1e00283
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/libraries/db/dependencies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ func TestDependencyExtract(t *testing.T) {
invalid("-invalidname")
invalid("_invalidname")
check("ciao", []string{"ciao"}, []string{""})
check("MyLib (>1.2.3)", []string{"MyLib"}, []string{">1.2.3"})
check("MyLib (>=1.2.3)", []string{"MyLib"}, []string{">=1.2.3"})
check("MyLib (<1.2.3)", []string{"MyLib"}, []string{"<1.2.3"})
check("MyLib (<=1.2.3)", []string{"MyLib"}, []string{"<=1.2.3"})
check("MyLib (!=1.2.3)", []string{"MyLib"}, []string{"!=1.2.3"})
check("MyLib (>1.0.0 && <2.1.0)", []string{"MyLib"}, []string{">1.0.0 && <2.1.0"})
check("MyLib (<1.0.0 || >2.0.0)", []string{"MyLib"}, []string{"<1.0.0 || >2.0.0"})
check("MyLib ((>0.1.0 && <2.0.0) || >2.1.0)", []string{"MyLib"}, []string{"(>0.1.0 && <2.0.0) || >2.1.0"})
check("MyLib ()", []string{"MyLib"}, []string{""})
check("MyLib (>=1.2.3),AnotherLib, YetAnotherLib (=1.0.0)",
[]string{"MyLib", "AnotherLib", "YetAnotherLib"},
[]string{">=1.2.3", "", "=1.0.0"})
invalid("MyLib (>=1.2.3)()")
invalid("MyLib (>=1.2.3),_aaaa")
invalid("MyLib,,AnotherLib")
invalid("MyLib (>=1.2.3)(),AnotherLib, YetAnotherLib (=1.0.0)")
invalid("MyLib(=1.2.3)")
check("Arduino Uno WiFi Dev Ed Library, LoRa Node (^2.1.2)",
[]string{"Arduino Uno WiFi Dev Ed Library", "LoRa Node"},
[]string{"", "^2.1.2"})
Expand Down
2 changes: 1 addition & 1 deletion internal/libraries/db/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func extractStringList(value string) []string {
return res
}

var re = regexp.MustCompile("^([a-zA-Z0-9](?:[a-zA-Z0-9._\\- ]*[a-zA-Z0-9])?) *(?: \\(([^()]*)\\))?$")
var re = regexp.MustCompile("^([a-zA-Z0-9](?:[a-zA-Z0-9._\\- ]*[a-zA-Z0-9])?) *(?: \\((.*)\\))?$")

// ExtractDependenciesList extracts dependencies from the "depends" field of library.properties
func ExtractDependenciesList(depends string) ([]*Dependency, error) {
Expand Down

0 comments on commit 1e00283

Please sign in to comment.