From 1f86ea0ac870ff439169bc87e1a1e96ad940cdb8 Mon Sep 17 00:00:00 2001 From: Ayoub-Mabrouk Date: Wed, 30 Oct 2024 22:48:16 +0100 Subject: [PATCH 1/2] Refactor getCharset function for conciseness and modern syntax - Utilized optional chaining to simplify charset retrieval - Improved JSDoc comments for clarity - Enhanced readability while maintaining functionality --- lib/types/urlencoded.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index 687745f8..15ca0aaf 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -188,13 +188,13 @@ function createQueryParser (options, extended) { * Get the charset of a request. * * @param {object} req + * @returns {string|undefined} * @api private */ - function getCharset (req) { try { - return (contentType.parse(req).parameters.charset || '').toLowerCase() - } catch (e) { + return contentType.parse(req).parameters.charset?.toLowerCase() + } catch { return undefined } } From 742016d1f7446e71cacd9126105e9ad9f030dad3 Mon Sep 17 00:00:00 2001 From: Ayoub Mabrouk <77799760+Ayoub-Mabrouk@users.noreply.github.com> Date: Sat, 2 Nov 2024 01:54:14 +0100 Subject: [PATCH 2/2] Update lib/types/urlencoded.js Co-authored-by: Sebastian Beltran --- lib/types/urlencoded.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/types/urlencoded.js b/lib/types/urlencoded.js index 15ca0aaf..0ce42a0d 100644 --- a/lib/types/urlencoded.js +++ b/lib/types/urlencoded.js @@ -188,7 +188,7 @@ function createQueryParser (options, extended) { * Get the charset of a request. * * @param {object} req - * @returns {string|undefined} + * @returns {(string|undefined)} * @api private */ function getCharset (req) {