Skip to content

Commit

Permalink
add check for if MAX_RANGE is NaN
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeScho committed Feb 10, 2021
1 parent 1ae6d4e commit e2512a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,11 @@ describe('for two IP addresses', () => {
const throwFn = () => getIPRange('128.0.0.0/1');
expect(throwFn).toThrow('Too many IPs in range. Total number: 2147483647. Max count is 5000, to increase, set the limit with the MAX_RANGE environment variable');
});

it('should throw if process.env.MAX_RANGE is NaN', () => {
process.env.MAX_RANGE = 'foo';

const throwFn = () => getIPRange('128.0.0.0/1');
expect(throwFn).toThrow('MAX_RANGE must be an integer');
});
});
3 changes: 3 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ const isCIDR = (ipCIDR: Address4 | Address6): boolean => Boolean(ipCIDR.parsedSu
const isRange = (ipRange: string): boolean => ipRange.indexOf('-') !== -1;

const getIPRange = (ip1: string, ip2?: string): Array<string> => {
if (process.env.MAX_RANGE && isNaN(parseInt(process.env.MAX_RANGE))) {
throw new Error('MAX_RANGE must be an integer');
}
maxRange = parseInt(process.env.MAX_RANGE || '10000');

const ip1v4 = getIPv4(ip1);
Expand Down

0 comments on commit e2512a1

Please sign in to comment.