intuit / intuit/CardParts

Fix Array `safeValue(at:)`

Open
#278 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
2.5k
Forks
221
PR merge metrics
No merged PRs in 30d

Description

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.
- Could you please let me know if I should create a new Issue for adding Unit tests.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.