-
Notifications
You must be signed in to change notification settings - Fork 23
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
Example for loose
option is not correct
#31
Comments
I added some tests to indicate how pick handles quality when |
@bamapookie it('selects the first matching language in loose mode, even when the accepted language is more restrictive', function(){
var result = parser.pick(['en', 'en-US', 'pl'], 'en-US;q=0.6', { loose: true });
assert.equal(result, 'en');
}); If "en-US" is accepted and "en-US" is supported it should return "en-US", why prefer a partial matching that is also less restrictive? |
@alex-piccione
I designed the test to match the requirement in this text. |
I'll update the test if you want. Let me know the criteria you want, and I'll update the readme as well. Example: |
In the previous comment I explained a specific example for a case where picking the first matching lang-region is not correct if a generic language exists (also if it came after in the accepted languages array).
it('1. selects the first matching language in loose mode, even when the accepted language is more restrictive', function(){
var result = parser.pick(['en', 'en-US', 'pl'], 'en-US', { loose: true });
assert.equal(result, 'en-US');
});
it('2. select less restrictive but proper language when availabe also if not first match', function(){
var result = parser.pick(['en-US', 'en'], 'en-GB', { loose: true });
assert.equal(result, 'en');
}); I just found someone else already suggested point 1: #34 (comment) |
Those 2 tests currently fail. They would require changing how loose is evaluated in the parser. My intention was to demonstrate how the code actually functions (except for the one failing test that needs to be changed from Edit: fixed and pushed. |
Perfect, I'll open an issue. |
In your README it states that
parser.pick(['fr', 'en'], 'en-GB,en-US;q=0.9,fr-CA;q=0.7,en;q=0.8');
would return"fr"
. But that's not correct IMO:I'd say this is indeed the expected behaviour, because there are to
en
with q=1 which should have preference over thefr
locale.Bonus: The README's example for the loose option is missing the
{ loose: true }
.The text was updated successfully, but these errors were encountered: