Skip to content

Commit

Permalink
[Tests] 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 943e411 commit 081a3ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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 @@ -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();
});
Expand Down Expand Up @@ -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();
Expand Down
11 changes: 5 additions & 6 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 @@ -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();
});

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

0 comments on commit 081a3ab

Please sign in to comment.