Skip to content

Commit

Permalink
Added logic to forbid non-numeric input to be treated as an integer
Browse files Browse the repository at this point in the history
This implements the solution discussed in
cypriss#83 (comment)
  • Loading branch information
lorcan committed Sep 26, 2019
1 parent 56bc47f commit d68c093
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/mutations/integer_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ def filter(data)

# Ensure it's the correct data type (Integer)
if !data.is_a?(Integer)
if data.is_a?(String) && data =~ /^-?\d/
data = data.to_i
if data.is_a?(String)
begin
data = Integer(data)
rescue ArgumentError
return [data, :integer]
end
else
return [data, :integer]
end
Expand Down

0 comments on commit d68c093

Please sign in to comment.