Skip to content

Commit

Permalink
fix: use var instead of const
Browse files Browse the repository at this point in the history
  • Loading branch information
IamLizu committed Nov 17, 2024
1 parent fa16d4a commit 219bfa4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ var parseValues = function parseQueryStringValues(str, options) {

var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str;
cleanStr = cleanStr.replace(/%5B/gi, '[').replace(/%5D/gi, ']');

// Calculate limit and split query string
var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit;
var parts = cleanStr.split(
options.delimiter,
options.throwOnLimitExceeded ? limit + 1 : limit
options.delimiter,
options.throwOnLimitExceeded ? limit + 1 : limit
);

// Check if parts exceed the parameter limit and handle it
if (options.throwOnLimitExceeded && parts.length > limit) {
throw new Error('Parameter limit exceeded. Only ' + limit + ' parameters allowed.');
}

var skipIndex = -1; // Keep track of where the utf8 sentinel was found
var i;

Expand Down Expand Up @@ -110,7 +110,7 @@ var parseValues = function parseQueryStringValues(str, options) {
} else {
key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key');

const currentArrayLength = isArray(obj[key]) ? obj[key].length : 0;
var currentArrayLength = isArray(obj[key]) ? obj[key].length : 0;
val = utils.maybeMap(
parseArrayValue(part.slice(pos + 1), options, currentArrayLength),
function (encodedVal) {
Expand Down
38 changes: 19 additions & 19 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,24 +1037,24 @@ test('parse()', function (t) {

t.test('parameter limit tests', function (st) {
st.test('does not throw error when within parameter limit', function (sst) {
const result = qs.parse('a=1&b=2&c=3', { parameterLimit: 5, throwOnLimitExceeded: true });
var result = qs.parse('a=1&b=2&c=3', { parameterLimit: 5, throwOnLimitExceeded: true });
sst.deepEqual(result, { a: '1', b: '2', c: '3' }, 'Should parse without errors');
sst.end();
});

st.test('throws error when throwOnLimitExceeded is present but not boolean', function (sst) {
sst.throws(
sst['throws'](
function () {
qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: 3, throwOnLimitExceeded: "true" });
qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: 3, throwOnLimitExceeded: 'true' });
},
new TypeError('`throwOnLimitExceeded` option must be a boolean'),
'Should throw error when throwOnLimitExceeded is present and not boolean'
);
sst.end();
});

st.test('throws error when parameter limit exceeded', function (sst) {
sst.throws(
sst['throws'](
function () {
qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: 3, throwOnLimitExceeded: true });
},
Expand All @@ -1063,48 +1063,48 @@ test('parse()', function (t) {
);
sst.end();
});

st.test('silently truncates when throwOnLimitExceeded is not given', function (sst) {
const result = qs.parse('a=1&b=2&c=3&d=4&e=5', { parameterLimit: 3 });
var result = qs.parse('a=1&b=2&c=3&d=4&e=5', { parameterLimit: 3 });
sst.deepEqual(result, { a: '1', b: '2', c: '3' }, 'Should parse and truncate silently');
sst.end();
});

st.test('silently truncates when parameter limit exceeded without error', function (sst) {
const result = qs.parse('a=1&b=2&c=3&d=4&e=5', { parameterLimit: 3, throwOnLimitExceeded: false });
var result = qs.parse('a=1&b=2&c=3&d=4&e=5', { parameterLimit: 3, throwOnLimitExceeded: false });
sst.deepEqual(result, { a: '1', b: '2', c: '3' }, 'Should parse and truncate silently');
sst.end();
});

st.test('allows unlimited parameters when parameterLimit set to Infinity', function (sst) {
const result = qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: Infinity });
var result = qs.parse('a=1&b=2&c=3&d=4&e=5&f=6', { parameterLimit: Infinity });
sst.deepEqual(result, { a: '1', b: '2', c: '3', d: '4', e: '5', f: '6' }, 'Should parse all parameters without truncation');
sst.end();
});

st.end();
});

t.test('array limit tests', function (st) {
st.test('does not throw error when array is within limit', function (sst) {
const result = qs.parse('a[]=1&a[]=2&a[]=3', { arrayLimit: 5, throwOnLimitExceeded: true });
var result = qs.parse('a[]=1&a[]=2&a[]=3', { arrayLimit: 5, throwOnLimitExceeded: true });
sst.deepEqual(result, { a: ['1', '2', '3'] }, 'Should parse array without errors');
sst.end();
});

st.test('throws error when throwOnLimitExceeded is present but not boolean for array limit', function (sst) {
sst.throws(
sst['throws'](
function () {
qs.parse('a[]=1&a[]=2&a[]=3&a[]=4', { arrayLimit: 3, throwOnLimitExceeded: "true" });
qs.parse('a[]=1&a[]=2&a[]=3&a[]=4', { arrayLimit: 3, throwOnLimitExceeded: 'true' });
},
new TypeError('`throwOnLimitExceeded` option must be a boolean'),
'Should throw error when throwOnLimitExceeded is present and not boolean for array limit'
);
sst.end();
});

st.test('throws error when array limit exceeded', function (sst) {
sst.throws(
sst['throws'](
function () {
qs.parse('a[]=1&a[]=2&a[]=3&a[]=4', { arrayLimit: 3, throwOnLimitExceeded: true });
},
Expand All @@ -1113,10 +1113,10 @@ test('parse()', function (t) {
);
sst.end();
});

st.end();
});

t.end();
});

Expand Down

0 comments on commit 219bfa4

Please sign in to comment.