-
-
Notifications
You must be signed in to change notification settings - Fork 20.9k
Open
Labels
Description
Environment information
Version: express 5.0.0-beta.3
Platform: Linux
Node.js version: 18.x
Any other relevant information: N/A
What steps will reproduce the bug?
- Import the utils module from Express
- Call the
setCharset
function with an uppercase Content-Type and a charset - Observe that the returned string converts the Content-Type to lowercase
const utils = require('express/lib/utils');
// Call setCharset with uppercase Content-Type
const contentType = 'TEXT/PLAIN';
const charset = 'UTF-8';
const result = utils.setCharset(contentType, charset);
console.log(result);
// Actual: 'text/plain; charset=UTF-8'
// Expected: 'TEXT/PLAIN; charset=UTF-8'
What is the expected behavior?
The function should preserve the original case of the Content-Type while adding the charset parameter. For example, when TEXT/PLAIN is provided as input, the output should be TEXT/PLAIN; charset=UTF-8.
What happens instead?
The function converts the Content-Type to lowercase, so TEXT/PLAIN becomes text/plain; charset=UTF-8 in the output.
Source of the issue
The issue is in the setCharset function in lib/utils.js.
The function uses contentType.parse() which normalizes the type to lowercase, and then contentType.format() which outputs the type in lowercase, resulting in the loss of the original case information.