Open dbertouille opened 2 years ago
Oh interesting, I assume you don't mean the first letter but following letters?
We don't have a strategy yet for post validating content generated by pattern :thinking:
Could you provide some invalid generated postcodes? We can use these e.g. for negative tests.
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`);
}
}
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?
No problem, I can work around it. Thanks for the quick response!
@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?
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]")}}');
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
, orU
are not used in postal codes. This is can cause the randomly generated codes to fail validation.Reference Documentation
Minimal reproduction code
Additional Context
No response
Environment Info
Which module system do you use?
Used Package Manager
npm