Skip to content

Commit 1e00283

Browse files
committed
Support parentheses in depends field constraints
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.
1 parent 1386c82 commit 1e00283

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

internal/libraries/db/dependencies_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ func TestDependencyExtract(t *testing.T) {
4848
invalid("-invalidname")
4949
invalid("_invalidname")
5050
check("ciao", []string{"ciao"}, []string{""})
51+
check("MyLib (>1.2.3)", []string{"MyLib"}, []string{">1.2.3"})
5152
check("MyLib (>=1.2.3)", []string{"MyLib"}, []string{">=1.2.3"})
53+
check("MyLib (<1.2.3)", []string{"MyLib"}, []string{"<1.2.3"})
54+
check("MyLib (<=1.2.3)", []string{"MyLib"}, []string{"<=1.2.3"})
55+
check("MyLib (!=1.2.3)", []string{"MyLib"}, []string{"!=1.2.3"})
56+
check("MyLib (>1.0.0 && <2.1.0)", []string{"MyLib"}, []string{">1.0.0 && <2.1.0"})
57+
check("MyLib (<1.0.0 || >2.0.0)", []string{"MyLib"}, []string{"<1.0.0 || >2.0.0"})
58+
check("MyLib ((>0.1.0 && <2.0.0) || >2.1.0)", []string{"MyLib"}, []string{"(>0.1.0 && <2.0.0) || >2.1.0"})
59+
check("MyLib ()", []string{"MyLib"}, []string{""})
5260
check("MyLib (>=1.2.3),AnotherLib, YetAnotherLib (=1.0.0)",
5361
[]string{"MyLib", "AnotherLib", "YetAnotherLib"},
5462
[]string{">=1.2.3", "", "=1.0.0"})
55-
invalid("MyLib (>=1.2.3)()")
5663
invalid("MyLib (>=1.2.3),_aaaa")
5764
invalid("MyLib,,AnotherLib")
58-
invalid("MyLib (>=1.2.3)(),AnotherLib, YetAnotherLib (=1.0.0)")
65+
invalid("MyLib(=1.2.3)")
5966
check("Arduino Uno WiFi Dev Ed Library, LoRa Node (^2.1.2)",
6067
[]string{"Arduino Uno WiFi Dev Ed Library", "LoRa Node"},
6168
[]string{"", "^2.1.2"})

internal/libraries/db/library.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func extractStringList(value string) []string {
6666
return res
6767
}
6868

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

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

0 commit comments

Comments
 (0)