Skip to content

Commit 37d19e7

Browse files
gxcsoccerfengmk2
authored andcommitted
fix: downward compatibility (#71)
1 parent ed7f966 commit 37d19e7

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

lib/v1/decoder.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ proto.readObject = function (withType) {
418418
// get
419419
var label = this.byteBuffer.getChar();
420420
var key;
421-
var t;
422421

423422
while (label !== 'z') {
424423
this.byteBuffer.position(this.byteBuffer.position() - 1);
@@ -427,8 +426,7 @@ proto.readObject = function (withType) {
427426
label = this.byteBuffer.getChar();
428427
// property name will auto transfer to a String type.
429428
debug('read object prop: %j with type: %s', key, withType);
430-
t = typeof key;
431-
if ((t === 'string' || t === 'number') && !/^this\$\d+$/.test(key)) {
429+
if (!/^this\$\d+$/.test(key)) {
432430
result.$[key] = value;
433431
}
434432
if (isMap) {

lib/v2/decoder.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -725,16 +725,12 @@ proto._readMap = function (map, withType) {
725725

726726
var k;
727727
var v;
728-
var t;
729728
// Z(0x5a) list/map terminator
730729
while (code !== 0x5a) {
731730
k = this.read(withType);
732731
v = this.read(withType);
733-
t = typeof k;
734-
735-
if (t === 'string' || t === 'number') {
736-
map[k] = v;
737-
}
732+
733+
map[k] = v;
738734
if (supportES6Map) {
739735
map.$map.set(k, v);
740736
}

test/map.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ describe('map.test.js', function() {
165165
it('should decode successful when key is null', function() {
166166
var data = new Buffer([77, 116, 0, 0, 78, 83, 0, 4, 110, 117, 108, 108, 122]);
167167
var rv = hessian.decode(data);
168-
rv.should.eql({});
168+
rv.should.eql({ null: 'null' });
169169

170170
if (!supportES6Map) {
171171
// pass if not support es6 Map
@@ -477,7 +477,7 @@ describe('map.test.js', function() {
477477
values[1].should.eql(166239);
478478

479479
var plainObject = JSON.parse(JSON.stringify(res.data));
480-
plainObject.should.eql({});
480+
plainObject.should.eql({ '[object Object]': 166239 });
481481
});
482482

483483
});

0 commit comments

Comments
 (0)