diff --git a/lib/buffer.js b/lib/buffer.js index 398357c6845568..466e08d293a1bf 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -683,8 +683,9 @@ Buffer.prototype[customInspectSymbol] = function inspect() { var str = ''; var max = exports.INSPECT_MAX_BYTES; str = this.toString('hex', 0, max).replace(/(.{2})/g, '$1 ').trim(); - if (this.length > max) - str += ' ... '; + const remaining = this.length - max; + if (remaining > 0) + str += ` ... ${remaining} more byte${remaining > 1 ? 's' : ''}`; return `<${this.constructor.name} ${str}>`; }; Buffer.prototype.inspect = Buffer.prototype[customInspectSymbol]; diff --git a/test/parallel/test-buffer-inspect.js b/test/parallel/test-buffer-inspect.js index aa703db67dfac4..9f91de700c7878 100644 --- a/test/parallel/test-buffer-inspect.js +++ b/test/parallel/test-buffer-inspect.js @@ -33,7 +33,7 @@ b.fill('1234'); let s = buffer.SlowBuffer(4); s.fill('1234'); -let expected = ''; +let expected = ''; assert.strictEqual(util.inspect(b), expected); assert.strictEqual(util.inspect(s), expected); diff --git a/test/parallel/test-buffer-prototype-inspect.js b/test/parallel/test-buffer-prototype-inspect.js index 9e6c66dc3da002..f13dda49f0dd45 100644 --- a/test/parallel/test-buffer-prototype-inspect.js +++ b/test/parallel/test-buffer-prototype-inspect.js @@ -19,5 +19,5 @@ const util = require('util'); { const buf = Buffer.from('x'.repeat(51)); - assert.ok(/^$/.test(util.inspect(buf))); + assert.ok(/^$/.test(util.inspect(buf))); }