Skip to content

Commit 4599ec6

Browse files
committed
Add missing -Infinity support
1 parent 18e2c56 commit 4599ec6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = function serialize(obj, options) {
103103
return '@__U-' + UID + '-' + (undefs.push(origValue) - 1) + '__@';
104104
}
105105

106-
if (origValue === Infinity) {
106+
if (type === 'number' && !isNaN(origValue) && !isFinite(origValue)) {
107107
return '@__I-' + UID + '-' + (infinities.push(origValue) - 1) + '__@';
108108
}
109109

@@ -209,7 +209,7 @@ module.exports = function serialize(obj, options) {
209209
}
210210

211211
if (type === 'I') {
212-
return 'Infinity';
212+
return infinities[valueIndex];
213213
}
214214

215215
var fn = functions[valueIndex];

test/unit/serialize.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ describe('serialize( obj )', function () {
388388
var d = eval(serialize(Infinity));
389389
expect(d).to.equal(Infinity);
390390
});
391+
392+
it('should serialize -Infinity', function () {
393+
expect(serialize(-Infinity)).to.equal('-Infinity');
394+
expect(serialize({t: [-Infinity]})).to.be.a('string').equal('{"t":[-Infinity]}');
395+
});
396+
397+
it('should deserialize -Infinity', function () {
398+
var d = eval(serialize(-Infinity));
399+
expect(d).to.equal(-Infinity);
400+
});
391401
});
392402

393403
describe('XSS', function () {

0 commit comments

Comments
 (0)