aboutsummaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/qs/test
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/qs/test')
-rw-r--r--deps/npm/node_modules/qs/test/parse.js61
-rw-r--r--deps/npm/node_modules/qs/test/stringify.js42
-rw-r--r--deps/npm/node_modules/qs/test/utils.js12
3 files changed, 106 insertions, 9 deletions
diff --git a/deps/npm/node_modules/qs/test/parse.js b/deps/npm/node_modules/qs/test/parse.js
index e451e91fe3..0f8fe4578a 100644
--- a/deps/npm/node_modules/qs/test/parse.js
+++ b/deps/npm/node_modules/qs/test/parse.js
@@ -2,7 +2,9 @@
var test = require('tape');
var qs = require('../');
+var utils = require('../lib/utils');
var iconv = require('iconv-lite');
+var SaferBuffer = require('safer-buffer').Buffer;
test('parse()', function (t) {
t.test('parses a simple string', function (st) {
@@ -230,7 +232,7 @@ test('parse()', function (t) {
});
t.test('parses buffers correctly', function (st) {
- var b = new Buffer('test');
+ var b = SaferBuffer.from('test');
st.deepEqual(qs.parse({ a: b }), { a: b });
st.end();
});
@@ -304,6 +306,13 @@ test('parse()', function (t) {
st.end();
});
+ t.test('allows for query string prefix', function (st) {
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
+ st.deepEqual(qs.parse('foo=bar', { ignoreQueryPrefix: true }), { foo: 'bar' });
+ st.deepEqual(qs.parse('?foo=bar', { ignoreQueryPrefix: false }), { '?foo': 'bar' });
+ st.end();
+ });
+
t.test('parses an object', function (st) {
var input = {
'user[name]': { 'pop[bob]': 3 },
@@ -388,6 +397,33 @@ test('parse()', function (t) {
st.end();
});
+ 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) {
var a = Object.create(null);
a.b = 'c';
@@ -504,16 +540,35 @@ test('parse()', function (t) {
result.push(parseInt(parts[1], 16));
parts = reg.exec(str);
}
- return iconv.decode(new Buffer(result), 'shift_jis').toString();
+ return iconv.decode(SaferBuffer.from(result), 'shift_jis').toString();
}
}), { 県: '大阪府' });
st.end();
});
+ t.test('receives the default decoder as a second argument', function (st) {
+ st.plan(1);
+ qs.parse('a', {
+ decoder: function (str, defaultDecoder) {
+ st.equal(defaultDecoder, utils.decode);
+ }
+ });
+ st.end();
+ });
+
t.test('throws error with wrong decoder', function (st) {
- st.throws(function () {
+ st['throws'](function () {
qs.parse({}, { decoder: 'string' });
}, new TypeError('Decoder has to be a function.'));
st.end();
});
+
+ t.test('does not mutate the options argument', function (st) {
+ var options = {};
+ qs.parse('a[b]=true', options);
+ st.deepEqual(options, {});
+ st.end();
+ });
+
+ t.end();
});
diff --git a/deps/npm/node_modules/qs/test/stringify.js b/deps/npm/node_modules/qs/test/stringify.js
index 711dae507d..165ac621fe 100644
--- a/deps/npm/node_modules/qs/test/stringify.js
+++ b/deps/npm/node_modules/qs/test/stringify.js
@@ -2,7 +2,9 @@
var test = require('tape');
var qs = require('../');
+var utils = require('../lib/utils');
var iconv = require('iconv-lite');
+var SaferBuffer = require('safer-buffer').Buffer;
test('stringify()', function (t) {
t.test('stringifies a querystring object', function (st) {
@@ -17,6 +19,16 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('adds query prefix', function (st) {
+ st.equal(qs.stringify({ a: 'b' }, { addQueryPrefix: true }), '?a=b');
+ st.end();
+ });
+
+ t.test('with query prefix, outputs blank string given an empty object', function (st) {
+ st.equal(qs.stringify({}, { addQueryPrefix: true }), '');
+ st.end();
+ });
+
t.test('stringifies a nested object', function (st) {
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
@@ -325,8 +337,8 @@ test('stringify()', function (t) {
});
t.test('stringifies buffer values', function (st) {
- st.equal(qs.stringify({ a: new Buffer('test') }), 'a=test');
- st.equal(qs.stringify({ a: { b: new Buffer('test') } }), 'a%5Bb%5D=test');
+ st.equal(qs.stringify({ a: SaferBuffer.from('test') }), 'a=test');
+ st.equal(qs.stringify({ a: { b: SaferBuffer.from('test') } }), 'a%5Bb%5D=test');
st.end();
});
@@ -452,15 +464,25 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('receives the default encoder as a second argument', function (st) {
+ st.plan(2);
+ qs.stringify({ a: 1 }, {
+ encoder: function (str, defaultEncoder) {
+ st.equal(defaultEncoder, utils.encode);
+ }
+ });
+ st.end();
+ });
+
t.test('throws error with wrong encoder', function (st) {
- st.throws(function () {
+ st['throws'](function () {
qs.stringify({}, { encoder: 'string' });
}, new TypeError('Encoder has to be a function.'));
st.end();
});
t.test('can use custom encoder for a buffer object', { skip: typeof Buffer === 'undefined' }, function (st) {
- st.equal(qs.stringify({ a: new Buffer([1]) }, {
+ st.equal(qs.stringify({ a: SaferBuffer.from([1]) }, {
encoder: function (buffer) {
if (typeof buffer === 'string') {
return buffer;
@@ -483,7 +505,7 @@ test('stringify()', function (t) {
mutatedDate.toISOString = function () {
throw new SyntaxError();
};
- st.throws(function () {
+ st['throws'](function () {
mutatedDate.toISOString();
}, SyntaxError);
st.equal(
@@ -525,7 +547,7 @@ test('stringify()', function (t) {
t.test('Edge cases and unknown formats', function (st) {
['UFO1234', false, 1234, null, {}, []].forEach(
function (format) {
- st.throws(
+ st['throws'](
function () {
qs.stringify({ a: 'b c' }, { format: format });
},
@@ -564,4 +586,12 @@ test('stringify()', function (t) {
st.end();
});
+ t.test('does not mutate the options argument', function (st) {
+ var options = {};
+ qs.stringify({}, options);
+ st.deepEqual(options, {});
+ st.end();
+ });
+
+ t.end();
});
diff --git a/deps/npm/node_modules/qs/test/utils.js b/deps/npm/node_modules/qs/test/utils.js
index 0721dd8ec6..eff4011a40 100644
--- a/deps/npm/node_modules/qs/test/utils.js
+++ b/deps/npm/node_modules/qs/test/utils.js
@@ -20,3 +20,15 @@ test('merge()', function (t) {
t.end();
});
+
+test('assign()', function (t) {
+ var target = { a: 1, b: 2 };
+ var source = { b: 3, c: 4 };
+ var result = utils.assign(target, source);
+
+ t.equal(result, target, 'returns the target');
+ t.deepEqual(target, { a: 1, b: 3, c: 4 }, 'target and source are merged');
+ t.deepEqual(source, { b: 3, c: 4 }, 'source is untouched');
+
+ t.end();
+});