File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -131,6 +131,8 @@ exports.stream = function (input) {
131
131
self . buffer = function ( name , bytes ) {
132
132
if ( typeof bytes === 'string' ) {
133
133
bytes = vars . get ( bytes ) ;
134
+ } else if ( bytes === undefined || bytes !== bytes ) {
135
+ bytes = 0 ;
134
136
}
135
137
136
138
getBytes ( bytes , function ( buf ) {
@@ -142,6 +144,8 @@ exports.stream = function (input) {
142
144
self . skip = function ( bytes ) {
143
145
if ( typeof bytes === 'string' ) {
144
146
bytes = vars . get ( bytes ) ;
147
+ } else if ( bytes === undefined || bytes !== bytes ) {
148
+ bytes = 0 ;
145
149
}
146
150
147
151
getBytes ( bytes , function ( ) {
@@ -272,6 +276,8 @@ exports.parse = function parse (buffer) {
272
276
self . buffer = function ( name , size ) {
273
277
if ( typeof size === 'string' ) {
274
278
size = vars . get ( size ) ;
279
+ } else if ( size === undefined || size !== size ) {
280
+ size = 0 ;
275
281
}
276
282
var buf = buffer . slice ( offset , Math . min ( buffer . length , offset + size ) ) ;
277
283
offset += size ;
@@ -283,6 +289,8 @@ exports.parse = function parse (buffer) {
283
289
self . skip = function ( bytes ) {
284
290
if ( typeof bytes === 'string' ) {
285
291
bytes = vars . get ( bytes ) ;
292
+ } else if ( bytes === undefined || bytes !== bytes ) {
293
+ bytes = 0 ;
286
294
}
287
295
offset += bytes ;
288
296
Original file line number Diff line number Diff line change @@ -52,3 +52,17 @@ test('loop', function (t) {
52
52
y : 9 ,
53
53
} ) ;
54
54
} ) ;
55
+
56
+ test ( 'NaN' , function ( t ) {
57
+ t . plan ( 3 ) ;
58
+ var res = binary . parse ( new Buffer ( [ 106 , 35 ] ) )
59
+ . buffer ( 'a' , NaN )
60
+ . word8 ( 'b' )
61
+ . skip ( NaN )
62
+ . word8 ( 'c' )
63
+ . vars
64
+ ;
65
+ t . equal ( res . a . length , 0 ) ;
66
+ t . equal ( res . b , 106 ) ;
67
+ t . equal ( res . c , 35 ) ;
68
+ } ) ;
You can’t perform that action at this time.
0 commit comments