File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ module.exports = function serialize(obj, options) {
103
103
return '@__U-' + UID + '-' + ( undefs . push ( origValue ) - 1 ) + '__@' ;
104
104
}
105
105
106
- if ( origValue === Infinity ) {
106
+ if ( type === 'number' && ! isNaN ( origValue ) && ! isFinite ( origValue ) ) {
107
107
return '@__I-' + UID + '-' + ( infinities . push ( origValue ) - 1 ) + '__@' ;
108
108
}
109
109
@@ -209,7 +209,7 @@ module.exports = function serialize(obj, options) {
209
209
}
210
210
211
211
if ( type === 'I' ) {
212
- return 'Infinity' ;
212
+ return infinities [ valueIndex ] ;
213
213
}
214
214
215
215
var fn = functions [ valueIndex ] ;
Original file line number Diff line number Diff line change @@ -388,6 +388,16 @@ describe('serialize( obj )', function () {
388
388
var d = eval ( serialize ( Infinity ) ) ;
389
389
expect ( d ) . to . equal ( Infinity ) ;
390
390
} ) ;
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
+ } ) ;
391
401
} ) ;
392
402
393
403
describe ( 'XSS' , function ( ) {
You can’t perform that action at this time.
0 commit comments