Skip to content

Commit

Permalink
librariesindex: Fix nil pointer. Refs arduino#1176
Browse files Browse the repository at this point in the history
Let the library index return the latest known version,
if a library without a version is updated.

Signed-off-by: Ruben Jenster <[email protected]>
  • Loading branch information
r10r committed Feb 7, 2021
1 parent 8b5179d commit feef910
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
if indexLib == nil {
return nil
}
if indexLib.Latest.Version.GreaterThan(lib.Version) {
if lib.Version == nil || indexLib.Latest.Version.GreaterThan(lib.Version) {
return indexLib.Latest
}
return nil
Expand Down
4 changes: 4 additions & 0 deletions arduino/libraries/librariesindex/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func TestIndexer(t *testing.T) {
require.NotNil(t, rtcUpdate)
require.Equal(t, "[email protected]", rtcUpdate.String())

rtcUpdateNoVersion := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: nil})
require.NotNil(t, rtcUpdateNoVersion)
require.Equal(t, "[email protected]", rtcUpdateNoVersion.String())

rtcNoUpdate := index.FindLibraryUpdate(&libraries.Library{Name: "RTCZero", Version: semver.MustParse("3.0.0")})
require.Nil(t, rtcNoUpdate)

Expand Down

0 comments on commit feef910

Please sign in to comment.