node-progress icon indicating copy to clipboard operation
node-progress copied to clipboard

"total" validation for NaN format

Open jacob-rogers opened this issue 7 years ago • 0 comments

Found some cases when total attribute may not be defined as Number/String/undefined, but could be a NaN format implicitly or not.

For example, my app using node-progress lib and has no request validation for incoming data Content-Length attribute. But it was actually passed into const total = parseInt(contentLength, 10) as undefined. And total has taken NaN.

Eventually, it throws the errors like described in #166:

complete = Array(Math.max(0, completeLength + 1)).join(this.chars.complete);
             ^

RangeError: Invalid array length
    at ProgressBar.render (.../node_modules/progress/lib/node-progress.js:155:14)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

where completeLength takes NaN from total.

Perhaps it could be more convenient to track if we missed a real total value transmitted if it throws when constructor of ProgressBar called.

I will be grateful if someone responds to this. Thanks.

jacob-rogers avatar Jan 31 '18 21:01 jacob-rogers