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 a54ca9e commit 0485440
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"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": {
Expand Down
5 changes: 3 additions & 2 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -230,7 +231,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 @@ -511,7 +512,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
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -325,8 +326,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 @@ -460,7 +461,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 0485440

Please sign in to comment.