Skip to content

Commit

Permalink
[Fix] use safer-buffer instead of Buffer constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Mar 20, 2018
1 parent 037f368 commit 73b3732
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"mkdirp": "^0.5.1",
"qs-iconv": "^1.0.4",
"safe-publish-latest": "^1.1.1",
"safer-buffer": "^2.0.2",
"tape": "^4.8.0"
},
"scripts": {
Expand Down
5 changes: 3 additions & 2 deletions test/parse.js
Expand Up @@ -4,6 +4,7 @@ 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) {
Expand Down Expand Up @@ -231,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();
});
Expand Down Expand Up @@ -539,7 +540,7 @@ 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();
Expand Down
7 changes: 4 additions & 3 deletions test/stringify.js
Expand Up @@ -4,6 +4,7 @@ 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) {
Expand Down Expand Up @@ -336,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();
});

Expand Down Expand Up @@ -481,7 +482,7 @@ test('stringify()', function (t) {
});

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;
Expand Down

0 comments on commit 73b3732

Please sign in to comment.