From 081a3ab2ca94b8ebe35ed7a018300996cb3694fd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 20 Mar 2018 22:22:47 +0000 Subject: [PATCH] [Tests] use `safer-buffer` instead of `Buffer` constructor https://github.com/ChALkeR/safer-buffer/blob/master/Porting-Buffer.md#variant-2 / https://github.com/nodejs/node/issues/19079 --- package.json | 14 ++++++++------ test/parse.js | 5 +++-- test/stringify.js | 11 +++++------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index cec10972..4bf439f8 100644 --- a/package.json +++ b/package.json @@ -24,16 +24,18 @@ }, "dependencies": {}, "devDependencies": { + "@ljharb/eslint-config": "^6.0.0", "browserify": "^13.0.1", - "tape": "^4.6.0", "covert": "^1.1.0", - "mkdirp": "^0.5.1", "eslint": "^3.1.0", - "@ljharb/eslint-config": "^6.0.0", - "parallelshell": "^2.0.0", + "evalmd": "^0.0.17", "iconv-lite": "^0.4.13", - "qs-iconv": "^1.0.3", - "evalmd": "^0.0.17" + "mkdirp": "^0.5.1", + "parallelshell": "^2.0.0", + "qs-iconv": "^1.0.4", + "safe-publish-latest": "^1.1.1", + "safer-buffer": "^2.0.2", + "tape": "^4.6.3" }, "scripts": { "pretest": "npm run --silent readme && npm run --silent lint", diff --git a/test/parse.js b/test/parse.js index 23e5e976..f6051312 100644 --- a/test/parse.js +++ b/test/parse.js @@ -3,6 +3,7 @@ var test = require('tape'); var qs = require('../'); var iconv = require('iconv-lite'); +var SaferBuffer = require('safer-buffer').Buffer; test('parse()', function (t) { t.test('parses a simple string', function (st) { @@ -221,7 +222,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(); }); @@ -501,7 +502,7 @@ test('parse()', function (t) { result.push(parseInt(parts[1], 16)); last = parts.index + parts[0].length; } - return iconv.decode(new Buffer(result), 'shift_jis').toString(); + return iconv.decode(SaferBuffer.from(result), 'shift_jis').toString(); } }), { 県: '大阪府' }); st.end(); diff --git a/test/stringify.js b/test/stringify.js index 3befb520..46be2334 100644 --- a/test/stringify.js +++ b/test/stringify.js @@ -3,6 +3,7 @@ var test = require('tape'); var qs = require('../'); var iconv = require('iconv-lite'); +var SaferBuffer = require('safer-buffer').Buffer; test('stringify()', function (t) { t.test('stringifies a querystring object', function (st) { @@ -193,8 +194,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(); }); @@ -288,10 +289,8 @@ test('stringify()', function (t) { 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]) }, { + t.test('can use custom encoder for a buffer object', { skip: typeof Buffer === 'undefined' }, function (st) { + st.equal(qs.stringify({ a: SaferBuffer.from([1]) }, { encoder: function (buffer) { if (typeof buffer === 'string') { return buffer;