Closed AnyhowStep closed 5 years ago
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.
Oh. I should pay more attention to the documentation than the internals... Thank you
I feel like passing
undefined
and passing an empty array should mean the same thing. But, I'm not sure how charset negotiation works.https://github.com/jshttp/negotiator/blob/89ab00343fd99d21df2a1ce03b832c1c0d27a599/lib/charset.js#L126
This other question is more contrived,
I'm looking at this line, in particular,
https://github.com/jshttp/negotiator/blob/89ab00343fd99d21df2a1ce03b832c1c0d27a599/lib/charset.js#L88
It says,
priority.o - spec.o
. So,getCharsetPriority()
will set theo
value of"SeCoNd"
to2
, the index of"second"
, instead of0
, the index of"SECOND"
.If we change that line to
spec.o - priority.o
, theo
value of"SeCoNd"
becomes0
, 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