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

fixed crash when no content-type #366

Closed
wants to merge 1 commit into from

Conversation

colinshr
Copy link

fixed crash when no content-type
to replicate just make a request like this, and it will crash
curl -v https://example.com/xxx -d '1' -H 'Content-Type:'

fixed crash when no content-type
@coveralls
Copy link

Coverage Status

coverage: 94.311%. remained the same
when pulling 1274e76 on colinshr:master
into fbee074 on richardgirges:master.

@@ -29,7 +29,7 @@ const hasAcceptableMethod = (req) => !UNACCEPTABLE_METHODS.has(req.method);
*/
const hasAcceptableContentType = (req) => {
const contType = req.headers['content-type'];
return contType.includes('boundary=') && ACCEPTABLE_CONTENT_TYPE.test(contType);
return contType && contType.includes('boundary=') && ACCEPTABLE_CONTENT_TYPE.test(contType);

Choose a reason for hiding this comment

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

Suggested change
return contType && contType.includes('boundary=') && ACCEPTABLE_CONTENT_TYPE.test(contType);
return !!contType?.includes('boundary=') && ACCEPTABLE_CONTENT_TYPE.test(contType);

reason for this suggestion is that, the initial implementation you provided has potential to cause the function to return the undefined or null or whatever falsy value that contType could potentially be. Kindly refer to the small demo i showed in the screenshot below for reference.

Screenshot 2023-11-21 at 2 06 04 PM

@RomanBurunkov
Copy link
Collaborator

Thanks, for checking this.
It was really helpful.

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.

4 participants