-
-
Notifications
You must be signed in to change notification settings - Fork 930
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_GB #2390
Comments
I think the tricky thing is knowing when to stop! Because in reality the first one-two chars can't be ANY A-Z, they can only be one of the https://en.wikipedia.org/wiki/List_of_postcode_areas_in_the_United_Kingdom valid postcode areas. So AB... and AL... are valid but not AA.. or AX... So then its tempting to hardcode those options. But then AL only goes up from 1...10, not 1...99. So maybe we should encode them, etc etc. The only true way to validate if a postcode is valid is to compare it against the full https://en.wikipedia.org/wiki/Postcode_Address_File In some cases i think its OK to return plausible but invalid data if the complexity costs of adding more validity checks are too high. I don't really know on which side of this arbitrary line this suggestion falls though! |
I understand what you're saying, but I think my suggestion is only related to format. The document I've linked to (from gov.uk, which in the UK means it's an official resource) documents the format of the post code which includes possible newly created post codes. It doesn't mention specific area codes (except for examples), only the format for what can and cannot be a post code. I understand that post codes created by faker may not match up to a real post code that actually exists, but I think it should not provide a post code that can never match because the format is incorrect. I fully agree that hardcoding current post code areas etc. is a step too far for what the library attempts to achieve, but I do believe that my request falls on the "worth doing" side of the line, but also I understand that this may add a maintenance burden, so I understand if you decide you don't agree :) |
i think you're right, however at the moment zipCode() uses |
IIRC we (I) already considered removing replaceSymbols* in favor a more standardized approach such as string replace, regex or fake patterns. |
Team Decision
|
I'll tackle this soon. Would you consider the switch from replaceSymbols to fake a breaking change? |
Here is a workaround, you can use until this is fixed: const zipCode = faker.helpers.fake([
'{{helpers.fromRegExp("[A-Z]{1,2}[0-9]{1,2} [0-9][ABDEFGHJLNPQRSTUWXYZ]{2}")}}',
'{{helpers.fromRegExp("[A-Z]{1,2}[0-9][A-Z] [0-9][ABDEFGHJLNPQRSTUWXYZ]{2}")}}',
]); |
Pre-Checks
Describe the bug
Very closely related to #1416 but for a different locale, so I though a new ticket would be appropriate.
Great Britain post codes also have some specific rules which means that some of the generated postcodes are invalid.
I have a REGEX string for validating if a GB post code is valid, so I'm sharing it here as hopefully it will help, even if only with automated testing. This regex is created based on this gov.uk document
I think the biggest tripping block for Faker here is that the final two letters cannot be C I K M O V.
For those who come across this issue, here's a workaround to get you going in modern TypeScript:
Minimal reproduction code
import { fakerEN_GB as faker } from "@faker-js/faker";
console.log(faker.location.zipCode());
Additional Context
In case the link breaks, here is that gov.uk document I mentioned.
Appendix_C_ILR_2017_to_2018_v1_Published_28April17.pdf
Environment Info
Which module system do you use?
Used Package Manager
npm
The text was updated successfully, but these errors were encountered: