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

More strict isFormDataLike #1872

Closed
ronag opened this issue Jan 20, 2023 · 5 comments
Closed

More strict isFormDataLike #1872

ronag opened this issue Jan 20, 2023 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@ronag
Copy link
Member

ronag commented Jan 20, 2023

isFormDataLike currently only checks that the constructor.name is 'FormData'. We should also check the interface as there are npm packages that have the correct name but wrong interface causing confusion where it's read as a FOrmData instead of a async generator..

@ronag ronag added bug Something isn't working good first issue Good for newcomers labels Jan 20, 2023
@jimmywarting

This comment was marked as off-topic.

@ronag
Copy link
Member Author

ronag commented Jan 20, 2023

@mateonunez
Copy link
Contributor

Hey @ronag, what about the following check?

function isFormDataLike (chunk) {
  return (
    (chunk &&
      chunk.constructor && chunk.constructor.name === 'FormData' &&
      /^(FormData)$/.test(chunk[Symbol.toStringTag])
    )
  )
}

Could this control be sufficient in your opinion? It checks if the instance of chunk contains the Symbol.toStringTag. It's extendible with other thirds parts (ex: formdata-node) and prevents confusion between packages like: form-data.

@ronag
Copy link
Member Author

ronag commented Jan 21, 2023

I'm not sure that is sufficient

@ronag
Copy link
Member Author

ronag commented Jan 21, 2023

That has the problem in the other direction. Third party module that are FormData like might not work. I think it's best to check constructor.name and make sure the expected API is available on the instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants