-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
Description
Describe the bug
Faker::Bank.account_number
can generate accounts with invalid characters, namely e
and -
. This happens because the implementation uses rand.to_s
faker/lib/faker/default/bank.rb
Line 22 in 8fbda8d
output += rand.to_s[2..] while output.length < digits |
To Reproduce
# frozen_string_literal: true
require "faker"
def find(digits:, max_iter: 1000000)
pattern = Regexp.new(/^[0-9a-zA-Z]+$/)
i = 1
while true do
a = Faker::Bank.account_number(digits: digits)
if a !~ pattern
puts "Found error on iteration #{i}: #{a}"
return
end
i += 1
return if i > max_iter
end
end
[1]pry(main)> find(digits: 20)
Found error on iteration 737: 3512553848424886e-05
Expected behavior
Account numbers should not have dashes.
Notes
We found this because we got a flaky in one of our tests.