File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ] ;
Original file line number Diff line number Diff 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 ( ) {
You can’t perform that action at this time.
0 commit comments