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

[WIP] Compare content type charsets case-insensitively #4717

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lilsweetcaligula
Copy link
Contributor

@lilsweetcaligula lilsweetcaligula commented Apr 28, 2023

Work In Progress. The solution depends on changes fastify/fast-content-type-parse#11

Refs: #4583

Checklist

function downcaseCharsetInContentType (contentType, parsed) {
if (parsed.parameters.charset) {
const indices = parsed.parametersIndices.charset
const valueEndsAt = indices.valueAt + parsed.parameters.charset.length
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@climba03003 climba03003 left a 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.

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
  }
}

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

Successfully merging this pull request may close these issues.

None yet

2 participants