intuit / CardParts

A reactive, card-based UI framework built on UIKit for iOS developers.
Other
2.52k stars 224 forks source link

Fix Array `safeValue(at:)` #278

Open mak-s opened 2 years ago

mak-s commented 2 years ago

Array extension safaValue(at:) method would crash if a negative index is used. https://github.com/intuit/CardParts/blob/3234eda81697e4a2e9e91f0a3673119dca996846/CardParts/src/Extensions/Array.swift#L11-L17

Though it does not introduce any bug at present as there is only one occurrence of safeValue usage, in CardPartHistogramView, which does not use a negative index, the extension method would crash if a negative index is used. https://github.com/intuit/CardParts/blob/27126a702b8011a274d93a6f0ba5cab18d1bab8c/CardParts/src/Classes/Card%20Parts/CardPartHistogramView.swift#L83-L85

Could we add a add a check for negative value to ensure that method work for all index values. (fix available in branch: https://github.com/mak-s/CardParts/tree/array_index_out_of_range)

Also, CardParts code coverage is less. I'd like to add some Unit tests for existing classes available in CardParts.