@@ -139,7 +139,26 @@ test('can compress memory and deduplicate points', function (t) {
139139 t . same ( polygon [ 0 ] , [ 1 , 0 ] , 'should preserve value' ) ;
140140 t . end ( ) ;
141141} ) ;
142+ test ( 'compress should skip invalid numbers' , function ( t ) {
143+ var INF = 1 / 0 ;
144+ // JSON.stringify doesn't support INF
145+ var original = [ [ INF ] , [ - INF ] , [ 0 ] , [ 0 ] , [ INF ] ] ;
146+ var compressedData = geobuf . compress ( original , new Map ( ) , new Map ( ) ) ;
147+ t . same ( [ [ INF ] , [ - INF ] , [ 0 ] , [ 0 ] , [ INF ] ] , compressedData ) ;
148+ t . strictEqual ( compressedData [ 2 ] , compressedData [ 3 ] ) ;
149+ t . notStrictEqual ( compressedData [ 0 ] , compressedData [ 4 ] ) ;
150+ t . end ( ) ;
151+ } ) ;
152+ test ( 'compress should skip NAN' , function ( t ) {
153+ var original = [ [ 0 , Number . NaN ] , [ 0 , null ] ] ;
154+ var compressedData = geobuf . compress ( original , new Map ( ) , new Map ( ) ) ;
155+ t . strictEqual ( compressedData [ 0 ] [ 0 ] , 0 ) ;
156+ t . same ( compressedData [ 1 ] , [ 0 , null ] ) ;
157+ t . ok ( Number . isNaN ( compressedData [ 0 ] [ 1 ] ) ) ;
158+ t . end ( ) ;
159+ } ) ;
142160function roundtripTest ( geojson ) {
161+
143162 return function ( t ) {
144163 var buf = geobuf . encode ( geojson , new Pbf ( ) ) ;
145164 var geojson2 = geobuf . decode ( new Pbf ( buf ) ) ;
0 commit comments