Fix error.decode API

This commit is contained in:
Kagami Hiiragi 2015-02-11 18:14:22 +03:00
parent 3f0b881a58
commit f619a066c6
2 changed files with 7 additions and 4 deletions

View File

@ -386,9 +386,12 @@ var error = exports.error = {
var vectorLength = decodedVectorLength.value; var vectorLength = decodedVectorLength.value;
var rest = decodedVectorLength.rest; var rest = decodedVectorLength.rest;
assert(rest.length >= vectorLength, "Buffer is too small"); assert(rest.length >= vectorLength, "Buffer is too small");
var vector = new Buffer(vectorLength); var vector = null;
rest.copy(vector); if (vectorLength) {
rest = rest.slice(vectorLength); vector = new Buffer(vectorLength);
rest.copy(vector);
rest = rest.slice(vectorLength);
}
var decodedErrorText = structs.var_str.decode(rest); var decodedErrorText = structs.var_str.decode(rest);
var length = ( var length = (

View File

@ -576,7 +576,7 @@ describe("Message types", function() {
var res = error.decode(encoded); var res = error.decode(encoded);
expect(res.fatal).to.equal(0); expect(res.fatal).to.equal(0);
expect(res.banTime).to.equal(0); expect(res.banTime).to.equal(0);
expect(res.vector).to.have.length(0); expect(res.vector).to.not.exist;
expect(res.errorText).to.equal("test"); expect(res.errorText).to.equal("test");
expect(res.length).to.equal(8); expect(res.length).to.equal(8);