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>
This commit is contained in:
parent
2ba8b23661
commit
60a974d200
@ -105,6 +105,10 @@ function fromObject(obj) {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj == null) {
|
||||||
|
throw new TypeError('must start with number, buffer, array or string');
|
||||||
|
}
|
||||||
|
|
||||||
if (obj instanceof ArrayBuffer) {
|
if (obj instanceof ArrayBuffer) {
|
||||||
return binding.createFromArrayBuffer(obj);
|
return binding.createFromArrayBuffer(obj);
|
||||||
}
|
}
|
||||||
|
@ -1181,3 +1181,11 @@ Buffer.poolSize = ps;
|
|||||||
assert.throws(function() {
|
assert.throws(function() {
|
||||||
Buffer(10).copy();
|
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…
x
Reference in New Issue
Block a user