(IAC-1414) Throw error in range() function when step size invalid #1161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Prior to this commit, on Ruby 2.7, the range() method would NOT
throw an ArgumentError exception if it was passed an invalid value as the
step size (3rd arg). Instead, it would return an array of size
1,000,000 with repeated integer values of the 2nd arg.
The function invokes Ruby's in built range method and
steptodefine a step size to increment / decrement by and then passes the
output to
first, limiting to the first 1,000,000 values.On Ruby < 2.7,
stepwould throw anArgumentErrorif the stepsize passed was
0:However, on Ruby 2.7, the
stepmethod returns an Enumerator thatwill then subsequently generate an Array of the size specified when
passed to
first, made up of the 2nd arg value (last):This is an issue, as the 3rd arg is passed to
to_i, which thenbecomes the step size. For any values that cannot be converted to
a positive / negative (or legit 0) Integer, a 0 is returned.
This commit will perform a check on the value of
stepand throwan ArgumentError if it is not zero.