fix: harden type checks for buildFormUrlEncodedPayload (#5811)

This commit is contained in:
Siddharth Gelera (reaper)
2025-10-16 13:31:13 +05:30
committed by GitHub
parent 4c3a9928bc
commit 2becf49542
3 changed files with 33 additions and 2 deletions

View File

@@ -8,9 +8,14 @@ const path = require('path');
* @returns {string} Returns a order respecting standard compliant string of form encoded values
*/
const buildFormUrlEncodedPayload = (params) => {
if (typeof params !== 'object') return '';
if (!Array.isArray(params)) return '';
const resultParams = new URLSearchParams();
for (const param of params) {
resultParams.append(param.name, param.value);
// Invalid items are ignored
if (typeof param !== 'object') continue;
if (!('name' in param)) continue;
resultParams.append(param.name, param.value ?? '');
}
return resultParams.toString();
};