diff --git a/lib/mini_defender/rules/integer.rb b/lib/mini_defender/rules/integer.rb index 0194762..cdafb72 100644 --- a/lib/mini_defender/rules/integer.rb +++ b/lib/mini_defender/rules/integer.rb @@ -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) diff --git a/lib/mini_defender/version.rb b/lib/mini_defender/version.rb index d01953b..9a45bba 100644 --- a/lib/mini_defender/version.rb +++ b/lib/mini_defender/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module MiniDefender - VERSION = "0.6.0" + VERSION = "0.6.1" end diff --git a/test/rules/integer_test.rb b/test/rules/integer_test.rb index 79e2ad4..bd63eda 100644 --- a/test/rules/integer_test.rb +++ b/test/rules/integer_test.rb @@ -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