Skip to content

Commit

Permalink
Support validating integers with leading zeros
Browse files Browse the repository at this point in the history
  • Loading branch information
ahoshaiyan committed Mar 14, 2024
1 parent d625dfd commit 73c868d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/mini_defender/rules/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def passes?(attribute, value, validator)
return true
end

value = value.to_s
# Remove leading zero so Integer will not treat it as octal
value = value
.to_s
.gsub(/^0+/, '')

if @mode == 'relaxed'
value = normalize_digits(value)
Expand Down
2 changes: 1 addition & 1 deletion lib/mini_defender/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module MiniDefender
VERSION = "0.6.0"
VERSION = "0.6.1"
end
4 changes: 4 additions & 0 deletions test/rules/integer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ def test_relaxed_passes_with_mixed_digits
assert @rule_relax.passes?('amount', '2٣', nil)
assert_equal 23, @rule_relax.coerce('2٣')
end

def test_passes_with_integer_with_leading_zero
assert @rule_relax.passes?('amount', '08', nil)
end
end

0 comments on commit 73c868d

Please sign in to comment.