Skip to content

Bank.account_number generates accounts with invalid characters #3114

Description

@sk-

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

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions