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 zip/postal codes when using locale en_CA #1416

Open
8 of 10 tasks
dbertouille opened this issue Oct 7, 2022 · 6 comments · May be fixed by #3235
Open
8 of 10 tasks

Invalid zip/postal codes when using locale en_CA #1416

dbertouille opened this issue Oct 7, 2022 · 6 comments · May be fixed by #3235
Assignees
Labels
c: bug Something isn't working c: locale Permutes locale definitions m: location Something is referring to the location module p: 1-normal Nothing urgent
Milestone

Comments

@dbertouille
Copy link

Pre-Checks

Describe the bug

When generating zip codes (postal codes) using the en_CA locale, invalid codes are generated. The characters D, F, I, O, Q, or U are not used in postal codes. This is can cause the randomly generated codes to fail validation.

Reference Documentation

Minimal reproduction code

const { faker } = require('@faker-js/faker');

faker.locale = 'en_CA';

console.log(faker.address.zipCode());

Additional Context

No response

Environment Info

System:
    OS: macOS 12.3
    CPU: (8) arm64 Apple M1 Pro
    Memory: 96.56 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.17.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.15.0 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 106.1.44.101
    Chrome: 105.0.5195.52
    Safari: 15.4
  npmPackages:
    @faker-js/faker: ^7.5.0 => 7.5.0

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

npm

@dbertouille dbertouille added c: bug Something isn't working s: pending triage Pending Triage labels Oct 7, 2022
@Shinigami92
Copy link
Member

Oh interesting, I assume you don't mean the first letter but following letters?

https://github.com/faker-js/faker/blob/7327e6e6fd4061f10647a5fabf437406c9ee8066/src/locales/en_CA/address/postcode.ts

We don't have a strategy yet for post validating content generated by pattern 🤔

Could you provide some invalid generated postcodes? We can use these e.g. for negative tests.

@dbertouille
Copy link
Author

For sure. Here are some examples.

P6V 1E1 is valid
V9O 9X4 is invalid
P7F 8L6 is invalid
G6O 7V0 is invalid
L6D 1K9 is invalid
E0T 2W7 is valid
G3L 4T8 is valid
E3P 6X3 is valid
J9A 4E7 is valid
N1Y 4H9 is valid

The following script can be used to generate more examples.

const { faker } = require('@faker-js/faker');

faker.locale = 'en_CA';

for (let i = 0; i < 10; i++) {
  const code = faker.address.zipCode();

  if (code.match(/^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/)) {
    console.log(`${code} is valid`);
  } else {
    console.log(`${code} is invalid`);
  }
}

@Shinigami92 Shinigami92 removed the s: pending triage Pending Triage label Oct 7, 2022
@Shinigami92 Shinigami92 moved this to Todo in Faker Roadmap Oct 7, 2022
@Shinigami92
Copy link
Member

Our internal resources are currently filled with preparing the move to start with v8, So I'm sorry if we cannot handle a fix right now.
Also we might think about a robust strategy to handle this bug in a higher order.

Until then, would it be okay to just use a loop until a valid postcode was generated?

@Shinigami92 Shinigami92 added the m: location Something is referring to the location module label Oct 7, 2022
@dbertouille
Copy link
Author

No problem, I can work around it. Thanks for the quick response!

@xDivisionByZerox xDivisionByZerox added the c: locale Permutes locale definitions label Oct 7, 2022
@ST-DDT ST-DDT added this to the vAnytime milestone Oct 20, 2024
@ST-DDT ST-DDT added the p: 1-normal Nothing urgent label Oct 20, 2024
@ST-DDT
Copy link
Member

ST-DDT commented Oct 20, 2024

@dbertouille Sorry, we kind of forgot about this issue.

Are you willing to create a PR for this now?
If yes, please check and update the pattern here:

You might have to duplicate some lines

e.g.

'A#? #?#' -> 'A#A #E#' + 'A#F #X#' + ...

Maybe multiply it out fully and then pick 100 random patterns?

@ST-DDT ST-DDT self-assigned this Oct 29, 2024
@ST-DDT ST-DDT linked a pull request Oct 29, 2024 that will close this issue
@ST-DDT
Copy link
Member

ST-DDT commented Oct 29, 2024

I created a PR to fix this issue:

Until the PR is merged, you can use the following workaround:

const zipCode = faker.helpers.fake('{{helpers.fromRegExp("[ABCEGHJ-NPRSTVXY][0-9][ABCEGHJ-NPRSTV-Z] [0-9][ABCEGHJ-NPRSTV-Z][0-9]")}}');

@ST-DDT ST-DDT linked a pull request Oct 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working c: locale Permutes locale definitions m: location Something is referring to the location module p: 1-normal Nothing urgent
Projects
No open projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

4 participants