Comparing version 6.5.0 to 6.5.1
@@ -0,1 +1,10 @@ | ||
## **6.5.1** | ||
- [Fix] Fix parsing & compacting very deep objects (#224) | ||
- [Refactor] name utils functions | ||
- [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape` | ||
- [Tests] up to `node` `v8.4`; use `nvm install-latest-npm` so newer npm doesn’t break older node | ||
- [Tests] Use precise dist for Node.js 0.6 runtime (#225) | ||
- [Tests] make 0.6 required, now that it’s passing | ||
- [Tests] on `node` `v8.2`; fix npm on node 0.6 | ||
## **6.5.0** | ||
@@ -2,0 +11,0 @@ - [New] add `utils.assign` |
126
dist/qs.js
@@ -83,32 +83,34 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Qs = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var parseObject = function parseObjectRecursive(chain, val, options) { | ||
if (!chain.length) { | ||
return val; | ||
} | ||
var parseObject = function (chain, val, options) { | ||
var leaf = val; | ||
var root = chain.shift(); | ||
for (var i = chain.length - 1; i >= 0; --i) { | ||
var obj; | ||
var root = chain[i]; | ||
var obj; | ||
if (root === '[]') { | ||
obj = []; | ||
obj = obj.concat(parseObject(chain, val, options)); | ||
} else { | ||
obj = options.plainObjects ? Object.create(null) : {}; | ||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; | ||
var index = parseInt(cleanRoot, 10); | ||
if ( | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
if (root === '[]') { | ||
obj = []; | ||
obj[index] = parseObject(chain, val, options); | ||
obj = obj.concat(leaf); | ||
} else { | ||
obj[cleanRoot] = parseObject(chain, val, options); | ||
obj = options.plainObjects ? Object.create(null) : {}; | ||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; | ||
var index = parseInt(cleanRoot, 10); | ||
if ( | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
obj = []; | ||
obj[index] = leaf; | ||
} else { | ||
obj[cleanRoot] = leaf; | ||
} | ||
} | ||
leaf = obj; | ||
} | ||
return obj; | ||
return leaf; | ||
}; | ||
@@ -351,3 +353,3 @@ | ||
if (typeof options.format === 'undefined') { | ||
options.format = formats.default; | ||
options.format = formats['default']; | ||
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) { | ||
@@ -436,3 +438,26 @@ throw new TypeError('Unknown format option provided.'); | ||
exports.arrayToObject = function (source, options) { | ||
var compactQueue = function compactQueue(queue) { | ||
var obj; | ||
while (queue.length) { | ||
var item = queue.pop(); | ||
obj = item.obj[item.prop]; | ||
if (Array.isArray(obj)) { | ||
var compacted = []; | ||
for (var j = 0; j < obj.length; ++j) { | ||
if (typeof obj[j] !== 'undefined') { | ||
compacted.push(obj[j]); | ||
} | ||
} | ||
item.obj[item.prop] = compacted; | ||
} | ||
} | ||
return obj; | ||
}; | ||
exports.arrayToObject = function arrayToObject(source, options) { | ||
var obj = options && options.plainObjects ? Object.create(null) : {}; | ||
@@ -448,3 +473,3 @@ for (var i = 0; i < source.length; ++i) { | ||
exports.merge = function (target, source, options) { | ||
exports.merge = function merge(target, source, options) { | ||
if (!source) { | ||
@@ -519,3 +544,3 @@ return target; | ||
exports.encode = function (str) { | ||
exports.encode = function encode(str) { | ||
// This code was originally written by Brian White (mscdex) for the io.js core querystring library. | ||
@@ -534,3 +559,3 @@ // It has been adapted here for stricter adherence to RFC 3986 | ||
if ( | ||
c === 0x2D // - | ||
c === 0x2D // - | ||
|| c === 0x2E // . | ||
@@ -573,42 +598,29 @@ || c === 0x5F // _ | ||
exports.compact = function (obj, references) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return obj; | ||
} | ||
exports.compact = function compact(value) { | ||
var queue = [{ obj: { o: value }, prop: 'o' }]; | ||
var refs = []; | ||
var refs = references || []; | ||
var lookup = refs.indexOf(obj); | ||
if (lookup !== -1) { | ||
return refs[lookup]; | ||
} | ||
for (var i = 0; i < queue.length; ++i) { | ||
var item = queue[i]; | ||
var obj = item.obj[item.prop]; | ||
refs.push(obj); | ||
if (Array.isArray(obj)) { | ||
var compacted = []; | ||
for (var i = 0; i < obj.length; ++i) { | ||
if (obj[i] && typeof obj[i] === 'object') { | ||
compacted.push(exports.compact(obj[i], refs)); | ||
} else if (typeof obj[i] !== 'undefined') { | ||
compacted.push(obj[i]); | ||
var keys = Object.keys(obj); | ||
for (var j = 0; j < keys.length; ++j) { | ||
var key = keys[j]; | ||
var val = obj[key]; | ||
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) { | ||
queue.push({ obj: obj, prop: key }); | ||
refs.push(val); | ||
} | ||
} | ||
return compacted; | ||
} | ||
var keys = Object.keys(obj); | ||
keys.forEach(function (key) { | ||
obj[key] = exports.compact(obj[key], refs); | ||
}); | ||
return obj; | ||
return compactQueue(queue); | ||
}; | ||
exports.isRegExp = function (obj) { | ||
exports.isRegExp = function isRegExp(obj) { | ||
return Object.prototype.toString.call(obj) === '[object RegExp]'; | ||
}; | ||
exports.isBuffer = function (obj) { | ||
exports.isBuffer = function isBuffer(obj) { | ||
if (obj === null || typeof obj === 'undefined') { | ||
@@ -615,0 +627,0 @@ return false; |
@@ -49,32 +49,34 @@ 'use strict'; | ||
var parseObject = function parseObjectRecursive(chain, val, options) { | ||
if (!chain.length) { | ||
return val; | ||
} | ||
var parseObject = function (chain, val, options) { | ||
var leaf = val; | ||
var root = chain.shift(); | ||
for (var i = chain.length - 1; i >= 0; --i) { | ||
var obj; | ||
var root = chain[i]; | ||
var obj; | ||
if (root === '[]') { | ||
obj = []; | ||
obj = obj.concat(parseObject(chain, val, options)); | ||
} else { | ||
obj = options.plainObjects ? Object.create(null) : {}; | ||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; | ||
var index = parseInt(cleanRoot, 10); | ||
if ( | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
if (root === '[]') { | ||
obj = []; | ||
obj[index] = parseObject(chain, val, options); | ||
obj = obj.concat(leaf); | ||
} else { | ||
obj[cleanRoot] = parseObject(chain, val, options); | ||
obj = options.plainObjects ? Object.create(null) : {}; | ||
var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; | ||
var index = parseInt(cleanRoot, 10); | ||
if ( | ||
!isNaN(index) | ||
&& root !== cleanRoot | ||
&& String(index) === cleanRoot | ||
&& index >= 0 | ||
&& (options.parseArrays && index <= options.arrayLimit) | ||
) { | ||
obj = []; | ||
obj[index] = leaf; | ||
} else { | ||
obj[cleanRoot] = leaf; | ||
} | ||
} | ||
leaf = obj; | ||
} | ||
return obj; | ||
return leaf; | ||
}; | ||
@@ -81,0 +83,0 @@ |
@@ -142,3 +142,3 @@ 'use strict'; | ||
if (typeof options.format === 'undefined') { | ||
options.format = formats.default; | ||
options.format = formats['default']; | ||
} else if (!Object.prototype.hasOwnProperty.call(formats.formatters, options.format)) { | ||
@@ -145,0 +145,0 @@ throw new TypeError('Unknown format option provided.'); |
@@ -14,3 +14,26 @@ 'use strict'; | ||
exports.arrayToObject = function (source, options) { | ||
var compactQueue = function compactQueue(queue) { | ||
var obj; | ||
while (queue.length) { | ||
var item = queue.pop(); | ||
obj = item.obj[item.prop]; | ||
if (Array.isArray(obj)) { | ||
var compacted = []; | ||
for (var j = 0; j < obj.length; ++j) { | ||
if (typeof obj[j] !== 'undefined') { | ||
compacted.push(obj[j]); | ||
} | ||
} | ||
item.obj[item.prop] = compacted; | ||
} | ||
} | ||
return obj; | ||
}; | ||
exports.arrayToObject = function arrayToObject(source, options) { | ||
var obj = options && options.plainObjects ? Object.create(null) : {}; | ||
@@ -26,3 +49,3 @@ for (var i = 0; i < source.length; ++i) { | ||
exports.merge = function (target, source, options) { | ||
exports.merge = function merge(target, source, options) { | ||
if (!source) { | ||
@@ -97,3 +120,3 @@ return target; | ||
exports.encode = function (str) { | ||
exports.encode = function encode(str) { | ||
// This code was originally written by Brian White (mscdex) for the io.js core querystring library. | ||
@@ -112,3 +135,3 @@ // It has been adapted here for stricter adherence to RFC 3986 | ||
if ( | ||
c === 0x2D // - | ||
c === 0x2D // - | ||
|| c === 0x2E // . | ||
@@ -151,42 +174,29 @@ || c === 0x5F // _ | ||
exports.compact = function (obj, references) { | ||
if (typeof obj !== 'object' || obj === null) { | ||
return obj; | ||
} | ||
exports.compact = function compact(value) { | ||
var queue = [{ obj: { o: value }, prop: 'o' }]; | ||
var refs = []; | ||
var refs = references || []; | ||
var lookup = refs.indexOf(obj); | ||
if (lookup !== -1) { | ||
return refs[lookup]; | ||
} | ||
for (var i = 0; i < queue.length; ++i) { | ||
var item = queue[i]; | ||
var obj = item.obj[item.prop]; | ||
refs.push(obj); | ||
if (Array.isArray(obj)) { | ||
var compacted = []; | ||
for (var i = 0; i < obj.length; ++i) { | ||
if (obj[i] && typeof obj[i] === 'object') { | ||
compacted.push(exports.compact(obj[i], refs)); | ||
} else if (typeof obj[i] !== 'undefined') { | ||
compacted.push(obj[i]); | ||
var keys = Object.keys(obj); | ||
for (var j = 0; j < keys.length; ++j) { | ||
var key = keys[j]; | ||
var val = obj[key]; | ||
if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) { | ||
queue.push({ obj: obj, prop: key }); | ||
refs.push(val); | ||
} | ||
} | ||
return compacted; | ||
} | ||
var keys = Object.keys(obj); | ||
keys.forEach(function (key) { | ||
obj[key] = exports.compact(obj[key], refs); | ||
}); | ||
return obj; | ||
return compactQueue(queue); | ||
}; | ||
exports.isRegExp = function (obj) { | ||
exports.isRegExp = function isRegExp(obj) { | ||
return Object.prototype.toString.call(obj) === '[object RegExp]'; | ||
}; | ||
exports.isBuffer = function (obj) { | ||
exports.isBuffer = function isBuffer(obj) { | ||
if (obj === null || typeof obj === 'undefined') { | ||
@@ -193,0 +203,0 @@ return false; |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://github.com/ljharb/qs", | ||
"version": "6.5.0", | ||
"version": "6.5.1", | ||
"repository": { | ||
@@ -28,7 +28,7 @@ "type": "git", | ||
"devDependencies": { | ||
"@ljharb/eslint-config": "^11.0.0", | ||
"@ljharb/eslint-config": "^12.2.1", | ||
"browserify": "^14.4.0", | ||
"covert": "^1.1.0", | ||
"editorconfig-tools": "^0.1.1", | ||
"eslint": "^3.19.0", | ||
"eslint": "^4.6.1", | ||
"evalmd": "^0.0.17", | ||
@@ -39,3 +39,3 @@ "iconv-lite": "^0.4.18", | ||
"safe-publish-latest": "^1.1.1", | ||
"tape": "^4.7.0" | ||
"tape": "^4.8.0" | ||
}, | ||
@@ -42,0 +42,0 @@ "scripts": { |
@@ -399,2 +399,29 @@ 'use strict'; | ||
t.test('does not crash when parsing deep objects', function (st) { | ||
var parsed; | ||
var str = 'foo'; | ||
for (var i = 0; i < 5000; i++) { | ||
str += '[p]'; | ||
} | ||
str += '=bar'; | ||
st.doesNotThrow(function () { | ||
parsed = qs.parse(str, { depth: 5000 }); | ||
}); | ||
st.equal('foo' in parsed, true, 'parsed has "foo" property'); | ||
var depth = 0; | ||
var ref = parsed.foo; | ||
while ((ref = ref.p)) { | ||
depth += 1; | ||
} | ||
st.equal(depth, 5000, 'parsed is 5000 properties deep'); | ||
st.end(); | ||
}); | ||
t.test('parses null objects correctly', { skip: !Object.create }, function (st) { | ||
@@ -533,3 +560,3 @@ var a = Object.create(null); | ||
t.test('throws error with wrong decoder', function (st) { | ||
st.throws(function () { | ||
st['throws'](function () { | ||
qs.parse({}, { decoder: 'string' }); | ||
@@ -536,0 +563,0 @@ }, new TypeError('Decoder has to be a function.')); |
@@ -477,3 +477,3 @@ 'use strict'; | ||
t.test('throws error with wrong encoder', function (st) { | ||
st.throws(function () { | ||
st['throws'](function () { | ||
qs.stringify({}, { encoder: 'string' }); | ||
@@ -508,3 +508,3 @@ }, new TypeError('Encoder has to be a function.')); | ||
}; | ||
st.throws(function () { | ||
st['throws'](function () { | ||
mutatedDate.toISOString(); | ||
@@ -551,3 +551,3 @@ }, SyntaxError); | ||
function (format) { | ||
st.throws( | ||
st['throws']( | ||
function () { | ||
@@ -554,0 +554,0 @@ qs.stringify({ a: 'b c' }, { format: format }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113401
2060