From cbb2f81bf1d761eb083461ef599c252a374b2fa6 Mon Sep 17 00:00:00 2001 From: Raoul Jaeckel Date: Tue, 12 Nov 2019 16:47:28 +0100 Subject: [PATCH] querystring: replace var with let/const PR-URL: https://github.com/nodejs/node/pull/30429 Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Gireesh Punathil Reviewed-By: Ruben Bridgewater Reviewed-By: Trivikram Kamat --- lib/querystring.js | 62 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/querystring.js b/lib/querystring.js index 9fac6e2627c08b..40f6d3dafb2b56 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -67,15 +67,15 @@ const unhexTable = [ // A safe fast alternative to decodeURIComponent function unescapeBuffer(s, decodeSpaces) { const out = Buffer.allocUnsafe(s.length); - var index = 0; - var outIndex = 0; - var currentChar; - var nextChar; - var hexHigh; - var hexLow; + let index = 0; + let outIndex = 0; + let currentChar; + let nextChar; + let hexHigh; + let hexLow; const maxLength = s.length - 2; // Flag to know if some hex chars have been decoded - var hasHex = false; + let hasHex = false; while (index < s.length) { currentChar = s.charCodeAt(index); if (currentChar === 43 /* '+' */ && decodeSpaces) { @@ -161,27 +161,27 @@ function stringify(obj, sep, eq, options) { sep = sep || '&'; eq = eq || '='; - var encode = QueryString.escape; + let encode = QueryString.escape; if (options && typeof options.encodeURIComponent === 'function') { encode = options.encodeURIComponent; } if (obj !== null && typeof obj === 'object') { - var keys = Object.keys(obj); - var len = keys.length; - var flast = len - 1; - var fields = ''; - for (var i = 0; i < len; ++i) { - var k = keys[i]; - var v = obj[k]; - var ks = encode(stringifyPrimitive(k)); + const keys = Object.keys(obj); + const len = keys.length; + const flast = len - 1; + let fields = ''; + for (let i = 0; i < len; ++i) { + const k = keys[i]; + const v = obj[k]; + let ks = encode(stringifyPrimitive(k)); ks += eq; if (Array.isArray(v)) { - var vlen = v.length; + const vlen = v.length; if (vlen === 0) continue; - var vlast = vlen - 1; - for (var j = 0; j < vlen; ++j) { + const vlast = vlen - 1; + for (let j = 0; j < vlen; ++j) { fields += ks; fields += encode(stringifyPrimitive(v[j])); if (j < vlast) @@ -204,7 +204,7 @@ function charCodes(str) { if (str.length === 0) return []; if (str.length === 1) return [str.charCodeAt(0)]; const ret = new Array(str.length); - for (var i = 0; i < str.length; ++i) + for (let i = 0; i < str.length; ++i) ret[i] = str.charCodeAt(i); return ret; } @@ -244,7 +244,7 @@ function parse(qs, sep, eq, options) { const sepLen = sepCodes.length; const eqLen = eqCodes.length; - var pairs = 1000; + let pairs = 1000; if (options && typeof options.maxKeys === 'number') { // -1 is used in place of a value like Infinity for meaning // "unlimited pairs" because of additional checks V8 (at least as of v5.4) @@ -255,22 +255,22 @@ function parse(qs, sep, eq, options) { pairs = (options.maxKeys > 0 ? options.maxKeys : -1); } - var decode = QueryString.unescape; + let decode = QueryString.unescape; if (options && typeof options.decodeURIComponent === 'function') { decode = options.decodeURIComponent; } const customDecode = (decode !== qsUnescape); - var lastPos = 0; - var sepIdx = 0; - var eqIdx = 0; - var key = ''; - var value = ''; - var keyEncoded = customDecode; - var valEncoded = customDecode; + let lastPos = 0; + let sepIdx = 0; + let eqIdx = 0; + let key = ''; + let value = ''; + let keyEncoded = customDecode; + let valEncoded = customDecode; const plusChar = (customDecode ? '%20' : ' '); - var encodeCheck = 0; - for (var i = 0; i < qs.length; ++i) { + let encodeCheck = 0; + for (let i = 0; i < qs.length; ++i) { const code = qs.charCodeAt(i); // Try matching key/value pair separator (e.g. '&')