Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid Iban generation for CR (Costa Rica) #538

Closed
SimonShvets opened this issue Apr 2, 2024 · 3 comments · Fixed by #546
Closed

Invalid Iban generation for CR (Costa Rica) #538

SimonShvets opened this issue Apr 2, 2024 · 3 comments · Fixed by #546

Comments

@SimonShvets
Copy link

Bogus NuGet Package

35.4.0

.NET Version

.NET 6.0

Visual Studio Version

17.8.4

What operating system are you using?

Windows

What locale are you using with Bogus?

en

Problem Description

correct iban format for CR -> CR05 0152 0200 1026 2840 66 (example)
Bogus library is generating -> CR37 0051 0009 0045 0014 1 (example)

LINQPad Example or Reproduction Steps

var iban = new Faker().Finance.Iban(false, "CR");

Expected Behavior

expected valid 22 symbols iban

Actual Behavior

invalid 21 symbols iban

Known Workarounds

No response

Could you help with a pull-request?

No

@dangerman
Copy link
Contributor

I looked into this and it seems like it's a bug that was already fixed in faker.js a couple years ago: faker-js/faker#643

In summary:

The Costa Rican IBAN format is missing an extra 0 (reserve number) before the banking code.
(For reference: https://bank-code.net/iban/structure/costa-rica-international-bank-account-number)

Locale data

Bogus IBAN generation appears to use the iban_formats from the locale data:

public string Iban(bool formatted = false, string countryCode = null)
{
var arr = this.GetArray("iban_formats");

And according to the documentation, this comes from:

  • the faker.js locale data from the faker submodule (from like 3 years ago, before the fix)
  • and the locales in data_extend, which take priority.

Proposed fix

We've already got iban_formats in the data_extend en locale, so we can just update it there and run gulp importLocales, right?

{
"country": "CR",
"total": 21,
"bban": [
{
"type": "n",
"count": 3
},
{
"type": "n",
"count": 14
}
],
"format": "CRkk bbbc cccc cccc cccc c"
},

@bchavez is it alright if I raise a PR with:

  • a fix in the en locale in data_extend
  • a test in Bogus.Tests/GitHubIssues?

@bchavez
Copy link
Owner

bchavez commented Apr 7, 2024

Hey, very great find and great investigation work @dangerman. 👍 Thank you for this.

If we already have a data_extend for iban formats, which it looks like we do; then yes, I would accept a PR/patch for this specific CR (Costa Rica) IBAN issue that updates data_extend:en/iban/cr.

You're absolutely correct on the proposed fix:

  • patch data_extend
  • write a unit test Bogus.Tests/GitHubIssues/Issue538.cs

and running gulp importLocales should gather all the JSON; merge data_extend, and finally write the necessary BSON resource files for Bogus.dll.

Just a few more points:

  • Reference this GH issue number Invalid Iban generation for CR (Costa Rica) #538 in your PR.
  • Keep the PR/change-set strictly focused on this kind of change (ie: don't include any code reformatting); keep the PR/changes strictly on topic. If you'd like to change something else off-topic; feel free to set up a new GH issue or PR for those off-topic changes and we can discuss. 👍

The README.md section for Building From Source should have the latest docs on the build basics for the Bogus repo (including node js dependencies etc):

Roadmap wise, right now Bogus is basically around fakerjs v5 API + dataset parity. Longer term, we'll be catching up to v8 API + datasets; which is why some of these datasets might be outdated and as we catch up; hopefully a lot of these issues will be resolved automatically.

bchavez pushed a commit that referenced this issue Apr 28, 2024
* Add test for Costa Rican IBAN

* Update CR IBAN format in extended locale data

* run gulp importLocales, excluding AR locale

* Update EN locale schema snapshot
@bchavez
Copy link
Owner

bchavez commented Apr 28, 2024

Thank you @dangerman for the PR; excellent and super great work.

The CR IBAN fix is now available in Bogus v35.5.1:

Thanks again for the bug report and PR fix. 👍 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants