Skip to content

Commit a545bb1

Browse files
committed
Remove redundant name validation from depends extraction regex
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. A check is done to make sure the specified library names have a valid format. This project was originally solely responsible for such checks. Since that time, a dedicated tool was created for validation of the library releases: Arduino Lint. Since Arduino Lint already does this check, and the DB entries are only added for releases which pass that check, the validation via the extraction regular expression is superfluous and only increases the maintenance burden for no benefit. The regular expression has a single purpose: extracting the components of the depends field elements. This more simple regular expression will accomplish that, given the data which has already been validated by Arduino Lint.
1 parent 1e00283 commit a545bb1

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

internal/libraries/db/dependencies_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ func TestDependencyExtract(t *testing.T) {
4545
require.Nil(t, dep)
4646
require.Error(t, err)
4747
}
48-
invalid("-invalidname")
49-
invalid("_invalidname")
5048
check("ciao", []string{"ciao"}, []string{""})
5149
check("MyLib (>1.2.3)", []string{"MyLib"}, []string{">1.2.3"})
5250
check("MyLib (>=1.2.3)", []string{"MyLib"}, []string{">=1.2.3"})
@@ -60,8 +58,8 @@ func TestDependencyExtract(t *testing.T) {
6058
check("MyLib (>=1.2.3),AnotherLib, YetAnotherLib (=1.0.0)",
6159
[]string{"MyLib", "AnotherLib", "YetAnotherLib"},
6260
[]string{">=1.2.3", "", "=1.0.0"})
63-
invalid("MyLib (>=1.2.3),_aaaa")
6461
invalid("MyLib,,AnotherLib")
62+
invalid("(MyLib)")
6563
invalid("MyLib(=1.2.3)")
6664
check("Arduino Uno WiFi Dev Ed Library, LoRa Node (^2.1.2)",
6765
[]string{"Arduino Uno WiFi Dev Ed Library", "LoRa Node"},

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("^([^()]+?) *(?: \\((.*)\\))?$")
7070

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

0 commit comments

Comments
 (0)