Skip to content

Commit 74a8415

Browse files
committed
Merge pull request #48 from node-modules/fix-array-encode
fix: array encode can be null
2 parents 657896b + c7bce6b commit 74a8415

File tree

8 files changed

+108
-108
lines changed

8 files changed

+108
-108
lines changed

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
sudo: false
12
language: node_js
23
node_js:
3-
- 'iojs-1'
4+
- '4'
5+
- '3'
6+
- '2'
7+
- '1'
48
- '0.12'
5-
- '0.11'
69
- '0.10'
7-
script: "make test-travis"
8-
after_script: "npm install coveralls@2 && cat ./coverage/lcov.info | coveralls"
10+
script:
11+
- "npm run lint && npm run test-cov"
12+
after_script:
13+
- "npm i codecov.io && cat ./coverage/coverage.json | ./node_modules/codecov.io/bin/codecov.io.js"

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 dead_horse
3+
Copyright (c) node-modules and other contributors.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

Makefile

Lines changed: 0 additions & 50 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@ hessian.js
33

44
[![NPM version][npm-image]][npm-url]
55
[![build status][travis-image]][travis-url]
6-
[![Test coverage][coveralls-image]][coveralls-url]
7-
[![Gittip][gittip-image]][gittip-url]
6+
[![Test coverage][codecov-image]][codecov-url]
87
[![David deps][david-image]][david-url]
9-
[![node version][node-image]][node-url]
108
[![npm download][download-image]][download-url]
119

1210
[npm-image]: https://img.shields.io/npm/v/hessian.js.svg?style=flat-square
1311
[npm-url]: https://npmjs.org/package/hessian.js
1412
[travis-image]: https://img.shields.io/travis/node-modules/hessian.js.svg?style=flat-square
1513
[travis-url]: https://travis-ci.org/node-modules/hessian.js
16-
[coveralls-image]: https://img.shields.io/coveralls/node-modules/hessian.js.svg?style=flat-square
17-
[coveralls-url]: https://coveralls.io/r/node-modules/hessian.js?branch=master
18-
[gittip-image]: https://img.shields.io/gittip/fengmk2.svg?style=flat-square
19-
[gittip-url]: https://www.gittip.com/fengmk2/
14+
[codecov-image]: https://codecov.io/github/node-modules/hessian.js/coverage.svg?branch=master
15+
[codecov-url]: https://codecov.io/github/node-modules/hessian.js?branch=master
2016
[david-image]: https://img.shields.io/david/node-modules/hessian.js.svg?style=flat-square
2117
[david-url]: https://david-dm.org/node-modules/hessian.js
22-
[node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
23-
[node-url]: http://nodejs.org/download/
2418
[download-image]: https://img.shields.io/npm/dm/hessian.js.svg?style=flat-square
2519
[download-url]: https://npmjs.org/package/hessian.js
2620

@@ -121,7 +115,7 @@ encoder.write(testObject);
121115
### Java Generic Map
122116

123117
```js
124-
// java code:
118+
// java code:
125119
// Map<Long, Integer> map = new HashMap<Long, Integer>();
126120
// map.put(123L, 123456);
127121
// map.put(123456L, 123);
@@ -384,41 +378,6 @@ xd8 - xef # one-octet compact long (-x8 to xf, xe0 is 0)
384378
xf0 - xff # two-octet compact long (-x800 to x7ff, xf8 is 0)
385379
```
386380

387-
## Authors
388-
389-
```
390-
$ git summary
391-
392-
project : hessian.js
393-
repo age : 4 weeks ago
394-
commits : 51
395-
active : 18 days
396-
files : 33
397-
authors :
398-
36 dead_horse 70.6%
399-
15 fengmk2 29.4%
400-
```
401-
402381
## Licences
403-
(The MIT License)
404-
405-
Copyright (c) 2014 dead-horse and other contributors
406-
407-
Permission is hereby granted, free of charge, to any person obtaining
408-
a copy of this software and associated documentation files (the
409-
'Software'), to deal in the Software without restriction, including
410-
without limitation the rights to use, copy, modify, merge, publish,
411-
distribute, sublicense, and/or sell copies of the Software, and to
412-
permit persons to whom the Software is furnished to do so, subject to
413-
the following conditions:
414-
415-
The above copyright notice and this permission notice shall be
416-
included in all copies or substantial portions of the Software.
417-
418-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
419-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
420-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
421-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
422-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
423-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
424-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
382+
383+
[MIT](LICENSE)

index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
/**!
2-
* hessian.js - index.js
3-
*
4-
* Copyright(c) 2014
2+
* Copyright(c) node-modules and other contributors.
53
* MIT Licensed
64
*
75
* Authors:
86
* dead_horse <dead_horse@qq.com> (http://deadhorse.me)
9-
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.github.com)
7+
* fengmk2 <fengmk2@gmail.com> (http://fengmk2.com)
108
*/
119

1210
'use strict';

lib/v1/encoder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ proto.writeArray = function (arr) {
394394
var className = ''; // empty string meaning: `javaObject.DEFAULT_CLASSNAME.list`
395395
var realArray = arr;
396396
if (!isSimpleArray) {
397+
if (is.object(arr) && is.nullOrUndefined(arr.$)) {
398+
return this.writeNull();
399+
}
397400
var isComplexArray = is.object(arr) &&
398401
is.string(arr.$class) && is.array(arr.$);
399402
if (!isComplexArray) {

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
"lib/"
99
],
1010
"scripts": {
11-
"test": "make test-all"
11+
"test": "mocha -R spec -t 15000 -r should test/*.test.js",
12+
"test-cov": "istanbul cover node_modules/.bin/_mocha -- -t 15000 -r should test/*.test.js",
13+
"lint": "jshint .",
14+
"autod": "autod -w --prefix '~' -e benchmark",
15+
"benchmark": "node benchmark/encode.js && node benchmark/decode.js"
1216
},
1317
"repository": {
1418
"type": "git",
@@ -30,7 +34,7 @@
3034
"homepage": "https://github.com/node-modules/hessian.js",
3135
"dependencies": {
3236
"byte": "~1.1.1",
33-
"debug": "~2.1.3",
37+
"debug": "~2.2.0",
3438
"is-type-of": "~0.3.1",
3539
"utility": "~1.4.0"
3640
},
@@ -44,5 +48,8 @@
4448
"long": "~2.2.3",
4549
"mocha": "*",
4650
"should": "~5.2.0"
51+
},
52+
"engines": {
53+
"node": ">= 0.10.0"
4754
}
4855
}

test/array.test.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**!
2+
* Copyright(c) node-modules and other contributors.
3+
* MIT Licensed
4+
*
5+
* Authors:
6+
* 汤尧 <tangyao@gmail.com> (http://tangyao.me)
7+
*/
8+
9+
"use strict";
10+
11+
/**
12+
* Module dependencies.
13+
*/
14+
15+
var should = require('should');
16+
var hessian = require('../');
17+
18+
describe('array.test.js', function () {
19+
it('should write null v1', function () {
20+
var b = hessian.encode([
21+
{
22+
$class: '[java.lang.Integer',
23+
$: null
24+
},
25+
{
26+
$class: '[java.lang.Integer',
27+
$: [1]
28+
}
29+
]);
30+
var a = hessian.decode(b);
31+
a.should.eql([null, [1]]);
32+
});
33+
34+
it('should write undefined v1', function () {
35+
var b = hessian.encode([
36+
{
37+
$class: '[java.lang.Integer',
38+
$: undefined
39+
},
40+
{
41+
$class: '[java.lang.Integer',
42+
$: [1]
43+
}
44+
]);
45+
var a = hessian.decode(b);
46+
a.should.eql([null, [1]]);
47+
});
48+
49+
it('should write null v2', function () {
50+
var b = hessian.encode([
51+
{
52+
$class: '[java.lang.Integer',
53+
$: null
54+
},
55+
{
56+
$class: '[java.lang.Integer',
57+
$: [1]
58+
}
59+
], '2.0');
60+
var a = hessian.decode(b, '2.0');
61+
a.should.eql([null, [1]]);
62+
});
63+
64+
it('should write undefined v2', function () {
65+
var b = hessian.encode([
66+
{
67+
$class: '[java.lang.Integer',
68+
$: undefined
69+
},
70+
{
71+
$class: '[java.lang.Integer',
72+
$: [1]
73+
}
74+
], '2.0');
75+
var a = hessian.decode(b, '2.0');
76+
a.should.eql([null, [1]]);
77+
});
78+
});

0 commit comments

Comments
 (0)