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

[Question] More preferredCharset() stuff #56

Closed
AnyhowStep opened this issue May 1, 2019 · 2 comments
Closed

[Question] More preferredCharset() stuff #56

AnyhowStep opened this issue May 1, 2019 · 2 comments

Comments

@AnyhowStep
Copy link

preferredCharsets("first,second,third")
//Actual Output: ["first", "second", "third"]

preferredCharsets("first,second,third", [])
//Actual Output: []
//Should the output, instead be, ["first", "second", "third"] ?

I feel like passing undefined and passing an empty array should mean the same thing. But, I'm not sure how charset negotiation works.

if (!provided) {


This other question is more contrived,

preferredCharsets("SECOND,first,second,third", ["SeCoNd", "first"])
//Actual Output: ["first", "SeCoNd"]
//Should the output, instead be, ["SeCoNd", "first"] ?

I'm looking at this line, in particular,

if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {

It says, priority.o - spec.o. So, getCharsetPriority() will set the o value of "SeCoNd" to 2, the index of "second", instead of 0, the index of "SECOND".

If we change that line to spec.o - priority.o, the o value of "SeCoNd" becomes 0, and will come before "first".

But, of course, realistically, who's going to send such a header where there are duplicate charsets, and they're not consecutive, with lower-priority available charsets requested in between?


You shouldn't have to do anything about the second question. I just like reading random pieces of code and poking at them :x

@dougwilson
Copy link
Contributor

I feel like passing undefined and passing an empty array should mean the same thing. But, I'm not sure how charset negotiation works.

So it's not that you're passing undefined in this API: it's that those are two different function signatures (https://github.com/jshttp/negotiator#methods-2):

charset()
Returns the most preferred charset from the client.

and

charset(availableCharsets)
Returns the most preferred charset from a list of available charsets.

@AnyhowStep
Copy link
Author

Oh. I should pay more attention to the documentation than the internals...
Thank you

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

No branches or pull requests

2 participants