Make it clear what arguments req.accepts* functions accept - #7452
Draft
krzysdz wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
#6088 changed the wording of
req.acceptsCharsets()docs and introduced a mistake which went unnoticed until #7451, where it was reported as a bug in code. Interestingly, 9 days later #6936 fixed the same mistake in docs forreq.accepts()and in #6936 (comment) @bjohansebas pointed out that Express had removed support for a comma delimited string before 4.0 release. Historically it looks more or less like this:jshhtp/accepts, which does not accept a single comma delimited string, but leaves it in the docs.req.accepts()toreq.acceptsCharsets(). The PR appears to be at least AI-assisted, if not completely AI-generated, but this does not explain why nobody noticed this during review. It is possible that the text wasn't based onreq.accepts(), but the LLM just wrote false information in docs and PR description - it sounds as if the author completely rewrote the method to extend the functionality, while in reality the changes to code were just cosmetic.req.accepts()docs.req.acceptsCharsets()docs become a part of Express.req.accepts()docs.Conclusions? Maybe I should check PRs after they're merged if I've ignored them before...
Description
This PR fixes this particular docs error and adds tests that cover the types of accepted arguments of
req.accepts*functions.Remaining things
All of these methods (
req.accepts,req.acceptsEncodings,req.acceptsCharsets,req.acceptsLanguages) do the same thing (except calling different methods ofaccepts), but are written in 3 different ways:var),.apply(accept, arguments)express/lib/request.js
Lines 127 to 130 in 023767f
express/lib/request.js
Lines 140 to 143 in 023767f
const)express/lib/request.js
Lines 171 to 174 in 023767f
express/lib/request.js
Lines 185 to 187 in 023767f
All of these functions are also documented completely differently, with or without examples and with JSDoc types not always reflecting the allowed argument types properly.
I'll try to make these functions and their docs more consistent with each other, so it'll be a draft PR for now.
TODO:
*Encodingsand*Languages)