Skip to content
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

Update Array safeValue(at:) behavior for negative index #279

Merged
merged 2 commits into from
Nov 4, 2021

Conversation

mak-s
Copy link
Contributor

@mak-s mak-s commented Oct 27, 2021

Before you make a Pull Request, read the important guidelines:

Issue Link 🔗 #278

  • Is this a bug fix or a feature?
  • Bug
  • Does it break any existing functionality?
  • No

Goals of this PR 🎉

  • Why is the change important?
  • Array Extension method to retrieve safeValue could crash if index is negative.

    Though it does not pose any issue at present as there is only one occurrence of safeValue(at:) usage, in CardPartHistogramView, which does not use a negative index, the extension method would crash if a negative index is used.

    for (index, entry) in barEntries.enumerated() {
    showEntry(index: index, entry: entry, animated: animated, oldEntry: oldValue.safeValue(at: index))
    }

  • What does this fix?
  • This PR aims to fix Array's `safeValue(at:)` method behaviour for negative index. If a negative index is used, the method would not crash with `index out of range` exception and return nil, thereby making it safe to use with any Integer value.
  • How far has it been tested?
  • Added unit test to test the behaviour of Array `safeValue` method for negative, zero, positive index and positive index out of range.

How Has This Been Tested 🔍

Please let us know if you have tested your PR and if we need to reproduce the issues. Also, please let us know if we need any relevant information for running the tests.

  • User Interface Testing
  • Application Testing

Test Configuration 👾

  • Xcode version:
  • 13.0
  • Device/Simulator
  • Simulator
  • iOS version || MacOSX version
  • iOS 15.0

Things to check on 🎯

  • My Pull Request code follows the coding standards and styles of the project
  • I have worked on unit tests and reviewed my code to the best of my ability
  • I have used comments to make other coders understand my code better
  • My changes are good to go without any warnings
  • I have added unit tests both for the happy and sad path
  • All of my unit tests pass successfully before pushing the PR
  • I have made sure all dependent downstream changes impacted by my PR are working

mak-s added 2 commits October 25, 2021 14:03
When accessing array elements, ensure index is a positive integer.
Add documentation for method `safeValue`
@badrinathvm badrinathvm self-requested a review November 4, 2021 18:20
@badrinathvm badrinathvm merged commit 0b29c98 into intuit:master Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants