Skip to content

librariesindex: Fix nil pointer. Refs #1176 #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (idx *Index) FindLibraryUpdate(lib *libraries.Library) *Release {
if indexLib == nil {
return nil
}
// library.Version is nil when when the version field in
// a library descriptor is malformed and could not be parsed.
if lib.Version == nil {
return indexLib.Latest
}
if indexLib.Latest.Version.GreaterThan(lib.Version) {
return indexLib.Latest
}
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