We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e51bbfd commit 3b27dd5Copy full SHA for 3b27dd5
lib/buffer.js
@@ -47,6 +47,11 @@ function alignPool() {
47
function Buffer(arg, encoding) {
48
// Common case.
49
if (typeof arg === 'number') {
50
+ if (typeof encoding === 'string') {
51
+ throw new Error(
52
+ 'If encoding is specified then the first argument must be a string'
53
+ );
54
+ }
55
// If less than zero, or NaN.
56
if (arg < 0 || arg !== arg)
57
arg = 0;
test/sequential/test-buffer-bad-overload.js
@@ -0,0 +1,15 @@
1
+'use strict';
2
+require('../common');
3
+const assert = require('assert');
4
+
5
+assert.doesNotThrow(function() {
6
+ new Buffer(10);
7
+});
8
9
+assert.throws(function() {
10
+ new Buffer(10, 'hex');
11
12
13
14
+ new Buffer('deadbeaf', 'hex');
15
0 commit comments