Browse Source

buffer: Fix incorrect Buffer.compare behavior

Fixes #7551

Signed-off-by: Trevor Norris <trev.norris@gmail.com>
archived-io.js-v0.10
Feross Aboukhadijeh 11 years ago
committed by Trevor Norris
parent
commit
522dda2f12
  1. 2
      lib/buffer.js
  2. 8
      test/simple/test-buffer.js

2
lib/buffer.js

@ -135,7 +135,7 @@ Buffer.compare = function compare(a, b) {
!(b instanceof Buffer)) !(b instanceof Buffer))
throw new TypeError('Arguments must be Buffers'); throw new TypeError('Arguments must be Buffers');
return internal.compare(b, a); return internal.compare(a, b);
}; };

8
test/simple/test-buffer.js

@ -1048,10 +1048,10 @@ assert.equal(c.compare(d), 1);
assert.equal(d.compare(b), 1); assert.equal(d.compare(b), 1);
assert.equal(b.compare(d), -1); assert.equal(b.compare(d), -1);
assert.equal(Buffer.compare(b, c), 1); assert.equal(Buffer.compare(b, c), -1);
assert.equal(Buffer.compare(c, d), -1); assert.equal(Buffer.compare(c, d), 1);
assert.equal(Buffer.compare(d, b), -1); assert.equal(Buffer.compare(d, b), 1);
assert.equal(Buffer.compare(b, d), 1); assert.equal(Buffer.compare(b, d), -1);
assert.throws(function() { assert.throws(function() {
var b = new Buffer(1); var b = new Buffer(1);

Loading…
Cancel
Save