Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8cb83ad

Browse files
committedFeb 12, 2021
librariesindex: Fix nil pointer. Refs #1176
Let the library index return the latest known version, if a library without a version is found. Signed-off-by: Ruben Jenster <[email protected]>
1 parent 8b5179d commit 8cb83ad

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
 

‎arduino/libraries/librariesindex/index.go

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package librariesindex
1717

1818
import (
19+
"fmt"
1920
"sort"
2021

2122
"github.com/arduino/arduino-cli/arduino/libraries"
@@ -136,6 +137,10 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
136137
if indexLib == nil {
137138
return nil
138139
}
140+
if lib.Version == nil {
141+
fmt.Printf("[WARN] version for library loaded from %s is nil\n", lib.InstallDir)
142+
return indexLib.Latest
143+
}
139144
if indexLib.Latest.Version.GreaterThan(lib.Version) {
140145
return indexLib.Latest
141146
}

‎arduino/libraries/librariesindex/index_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ func TestIndexer(t *testing.T) {
7878
require.NotNil(t, rtcUpdate)
7979
require.Equal(t, "RTCZero@1.6.0", rtcUpdate.String())
8080

81+
rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil})
82+
require.NotNil(t, rtcUpdateNoVersion)
83+
require.Equal(t, "RTCZero@1.6.0", rtcUpdateNoVersion.String())
84+
8185
rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("3.0.0")})
8286
require.Nil(t, rtcNoUpdate)
8387

0 commit comments

Comments
 (0)
Please sign in to comment.