Browse Source

buffer: fix missing null/undefined check

The new implementation of Buffer missed the check for null/undefined as
the first argument to new Buffer(). Reintroduce the check and add test.

Fix: e8734c0 "buffer: implement Uint8Array backed Buffer"
Fix: https://github.com/nodejs/io.js/issues/2194
PR-URL: https://github.com/nodejs/io.js/pull/2195
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rod Vagg <rod@vagg.org>
v4.0.0-rc
Trevor Norris 9 years ago
committed by Rod Vagg
parent
commit
60a974d200
  1. 4
      lib/buffer.js
  2. 8
      test/parallel/test-buffer.js

4
lib/buffer.js

@ -105,6 +105,10 @@ function fromObject(obj) {
return b;
}
if (obj == null) {
throw new TypeError('must start with number, buffer, array or string');
}
if (obj instanceof ArrayBuffer) {
return binding.createFromArrayBuffer(obj);
}

8
test/parallel/test-buffer.js

@ -1181,3 +1181,11 @@ Buffer.poolSize = ps;
assert.throws(function() {
Buffer(10).copy();
});
assert.throws(function() {
new Buffer();
}, /must start with number, buffer, array or string/);
assert.throws(function() {
new Buffer(null);
}, /must start with number, buffer, array or string/);

Loading…
Cancel
Save