Skip to content

Upgrade content-type#7234

Open
blakeembrey wants to merge 2 commits into
masterfrom
be/upgrade-content-type
Open

Upgrade content-type#7234
blakeembrey wants to merge 2 commits into
masterfrom
be/upgrade-content-type

Conversation

@blakeembrey
Copy link
Copy Markdown
Member

Only used in

express/lib/utils.js

Lines 225 to 238 in f873ac2

exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
. There will be a minor change in behavior for invalid content-type headers as parse no longer fails but instead does its best, but the format below it will validate anything that was parsed.

This only leaves edge cases like unterminated " or trailing content after ""xyz as omitted. 100% backward compatibility can be achieved for these edge cases if its wanted, but I'm not sure it's worth it.

Version 2 of content-type was focused on performance and since this is the only method in the package using it, it's not a critical upgrade and would only serve to deduplicate with any dependencies that also upgrade.

@blakeembrey blakeembrey requested a review from a team May 11, 2026 21:19
@blakeembrey
Copy link
Copy Markdown
Member Author

Including a type-is bump since it's now using content-type@2 as well.

Copy link
Copy Markdown
Member

@LinusU LinusU left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Copy Markdown
Member

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

There will be a minor change in behavior for invalid content-type headers as parse no longer fails but instead does its best, but the format below it will validate anything that was parsed.

please add tests for that case. I’m not going to block it because my time is very limited by the time you make the change, but if there are any minor changes, please add them to the tests as well.

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.

3 participants