-
Notifications
You must be signed in to change notification settings - Fork 9
Add files via upload #8
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
base: master
Are you sure you want to change the base?
Conversation
Adds badge text-based feedback indicating invalid |accept-language| strings, a single |accept-language| substring, multiple valid |accept-language| substrings, and all |accept-language| have |;q=0|.
Changed an operator from `>=` to `===`. No effect on functionality, but the latter is more correct.
Added a Unicode variation selector 16 (`\u{fe0f}`) character after the warning sign (⚠) character to force a multicolor emoji version of the character since that's more readable.
Fix use of double quotation marks to use single quotation marks.
Removed two unnecessary else statements. (No need for them since previous blocks use `return`.)
Added an `if` statement that accounts for empty strings so they aren't treated as errors.
Woohoo! This seems to work really well. The use of emoji to indicate errors is super clever. I think we can determine the highest qvalue language more concisely via map/reduce. I believe this does the same thing, given a valid input string: let best = (input) => {
return input.split(',')
.map(token => token.trim().split(';q='))
.map(([lang, qval]) => [lang, qval ? parseFloat(qval) : 1])
.reduce(([bestLang, bestQval], [lang, qval]) => {
if (qval > bestQval) {
return [lang, qval];
} else if (qval === bestQval) {
return ['mul', bestQval]
} else {
return [bestLang, bestQval];
}
}, ['', -1]);
} For example:
Does that function look right to you? |
@callahad I've never used the The code is incomplete though since it doesn't evaluate the validity of the string. One can't accurately determine the It also doesn't handle a This code, based on yours, seems to handle the missing cases:
(There's no emoji for 🛇 on Windows. This just future-proofs the character.) |
It seems that my regex is actually inaccurate. Apparently RFC2616 is superseded by RFC7231, which allows both numbers (in addition to letters) after the language-range's hyphen-minus character and optional whitespace (spaces and tabs) around the Still can't figure out what the formal rules are for whitespace around commas. |
So RFC3282 specifies a ridiculously permissive model that allows I have no idea how to implement comment detection since I can't understand what the spec means when it defines The next best solution seems to be (A) to prohibit entry of anything other than There's also (C): figure out comment detection, but that may be awhile. Using
|
Adds badge text-based feedback indicating invalid |accept-language| strings, a single |accept-language| substring, multiple valid |accept-language| substrings, and all |accept-language| having |;q=0|.
Not sure if "q=0" is the best feedback. It could be "!language" or something along those lines.