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

isLocale doesn't work anymore (returns true on wrong locals) #2342

Open
sbatezat opened this issue Nov 26, 2023 · 5 comments
Open

isLocale doesn't work anymore (returns true on wrong locals) #2342

sbatezat opened this issue Nov 26, 2023 · 5 comments
Labels

Comments

@sbatezat
Copy link

Describe the bug
I was using isLocale to check locale string like "en-US" or "fr-CA" and so on.
Everything was working fine on 13.9.0, but today I'm trying to upgrade to validator 13.11.0 and my unit tests are failing.

Examples
validator.isLocale("french"), validator.isLocale("frenchy") returns true in validator 13.11.0, returns false on validator 13.9.0

@WikiRik
Copy link
Member

WikiRik commented Nov 26, 2023

This is due to #2189
With that, can you figure out why it accepts those strings and what we need to change to fix it if that behaviour is incorrect?

@sbatezat
Copy link
Author

sbatezat commented Nov 27, 2023

I'm not an expert on regexp.
But your 'language' rule seems way too permissive :

const language = (([a-zA-Z]{2,3}(-${extlang})?)|([a-zA-Z]{5,8}));

I admire the fact you want to manage these locales with regexp, but I've got the feeling rules are too complex to handle it like that. Result is that isLocale returns true for many strings that are not locale at all...

Storing all locales (at least some part to build them) in an array could seem ugly and absurd at first, but well, it handles every specific rules and edge cases... that you don't manage with regexp.

@manojmula
Copy link

as mentioned by @WikiRik , it seems that the #2189 changes seem to have included language with generic language acceptance, as you mentioned, so if this need to be changed, will be happy to help regarding this. @sbatezat

@sbatezat
Copy link
Author

sbatezat commented Dec 22, 2023

Obviously it needs to be changed.
To fix the fact isLocal() calls was not working with every good string (#2100) you made it working for almost every bad string...

@efbgirotto
Copy link

Language tags are described in RFC4647 and locale tags are described in RFC5646. I don't think they can coexist in same isLocale validation function.

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

No branches or pull requests

4 participants