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
[WIP] Compare content type charsets case-insensitively #4717
base: main
Are you sure you want to change the base?
[WIP] Compare content type charsets case-insensitively #4717
Conversation
function downcaseCharsetInContentType (contentType, parsed) { | ||
if (parsed.parameters.charset) { | ||
const indices = parsed.parametersIndices.charset | ||
const valueEndsAt = indices.valueAt + parsed.parameters.charset.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why compare with lower-case require such complicated changes.
fastify/lib/contentTypeParser.js
Lines 364 to 381 in f1737b3
function compareContentType (contentType, parserListItem) { | |
if (parserListItem.isEssence) { | |
// we do essence check | |
return contentType.type.indexOf(parserListItem) !== -1 | |
} else { | |
// when the content-type includes parameters | |
// we do a full-text search | |
// reject essence content-type before checking parameters | |
if (contentType.type.indexOf(parserListItem.type) === -1) return false | |
for (const key of parserListItem.parameterKeys) { | |
// reject when missing parameters | |
if (!(key in contentType.parameters)) return false | |
// reject when parameters do not match | |
if (contentType.parameters[key] !== parserListItem.parameters[key]) return false | |
} | |
return true | |
} | |
} |
function compareContentType (contentType, parserListItem) {
if (parserListItem.isEssence) {
// we do essence check
return contentType.type.indexOf(parserListItem) !== -1
} else {
// when the content-type includes parameters
// we do a full-text search
// reject essence content-type before checking parameters
if (contentType.type.indexOf(parserListItem.type) === -1) return false
for (const key of parserListItem.parameterKeys) {
// reject when missing parameters
if (!(key in contentType.parameters)) return false
// when key is charset, compare with lowercase
if (key.length === 7 && key === 'charset' && contentType.parameters[key].toLowerCase() !== parserListItem.parameters[key].toLowerCase()) return false
// reject when parameters do not match
else if (contentType.parameters[key] !== parserListItem.parameters[key]) return false
}
return true
}
}
Work In Progress. The solution depends on changes fastify/fast-content-type-parse#11
Refs: #4583
Checklist
npm run test
andnpm run benchmark
and the Code of conduct