Closed trivikr closed 3 years ago
Example fix without changing the prior error:
if (typeof this.capacity !== 'number' || this.capacity <= 0)
if (!isFinite(this.capacity) || Math.floor(this.capacity) !== this.capacity)
throw new Error('mnemonist/lru-cache: capacity should be a finite positive integer.');
throw new Error('mnemonist/lru-cache: capacity should be positive number.');
Hello @trivikr. Looks good to me. Do you want to open a PR with this change?
Do you want to open a PR with this change?
PR posted at https://github.com/Yomguithereal/mnemonist/pull/166
Describe the issue
LRUCache throws "Invalid array length" as an error if float value is passed to it.
Steps to reproduce
Run the following code with
mnemonist@0.38.3
Observed behavior
The following error is thrown:
Expected behavior
A custom error can be thrown on this line instead after adding a check for integer: https://github.com/Yomguithereal/mnemonist/blob/825538adaf1daee4b9ce3f6c073956ed4211ea1e/lru-cache.js#L40-L41