Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions lib/reader2.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,51 @@ Reader.prototype.readClassDef = function(data) {
}
};

Reader.prototype.parseUTF8Char = function(data) {
if (data)
this.reader = new BufferReader(data);

var ch = this.reader.nextUInt8();
this.reader.move(-1);

if (ch < 0x80) {
return this.reader.nextString(1);
} else if ((ch & 0xe0) == 0xc0) {
return this.reader.nextString(2);
}
else if ((ch & 0xf0) == 0xe0) {
return this.reader.nextString(3);
}
else
throw new Error("bad utf-8 encoding at " + ch);
}

Reader.prototype.parseUTF8String = function(length) {
var len = length;
var str = '';
while (len) {
str += this.parseUTF8Char();
len -= 1;
}
return str;
}

Reader.prototype.readString = function(data) {
if (data)
this.reader = new BufferReader(data);

var code = this.reader.nextUInt8();
if (code >= 0 && code < 32) {
return this.reader.nextString(code);
return this.parseUTF8String(code);
} else if (code >= 0x30 && code <= 0x33) {
this.reader.move(-1);
var len = this.reader.nextUInt16BE() - 0x3000;
return this.reader.nextString(len);
var len = (code - 0x30) * 256 + this.reader.nextUInt8();
return this.parseUTF8String(len);
} else if (code === 0x53) {
var len = this.reader.nextUInt16BE();
return this.reader.nextString(len);
return this.parseUTF8String(len);
} else if (code === 0x52) {
var len = this.reader.nextUInt16BE();
return this.reader.nextString(len) + this.readString();
return this.parseUTF8String(len) + this.readString();
}
};

Expand Down
6 changes: 4 additions & 2 deletions test/test2.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ describe('hessian 2.0 test', function() {

MAKE_REPLYTEST('replyUntypedMap_' + i, null, function(res) {
if (i < 3) {
assert.lengthOf(res.keys(), i);
if (res.keys().length) assert.lengthOf(res.keys(), i);
else assert.equal(res.size, i);
} else {
assert.lengthOf(res.keys(), 1);
if (res.keys().length) assert.lengthOf(res.keys(), 1);
else assert.equal(res.size, 1);
}
});
});
Expand Down