mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-09-12 11:15:37 -05:00
IPTools: Fix CIDR ranges at 128.* and up (#11466)
Some checks are pending
Node.js CI / build (18.x) (push) Waiting to run
Some checks are pending
Node.js CI / build (18.x) (push) Waiting to run
This commit is contained in:
@@ -151,6 +151,7 @@ export const IPTools = new class {
|
||||
// does << with signed int32s.
|
||||
if (low === null || !bits || bits < 2 || bits > 32) return null;
|
||||
low &= ~((1 << (32 - bits)) - 1);
|
||||
if (low < 0) low += 4294967296;
|
||||
const high = low + (1 << (32 - bits)) - 1;
|
||||
return { minIP: low, maxIP: high };
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ describe("IP tools", () => {
|
||||
assert.equal(IPTools.getCidrRange('10.69.42.69/8').minIP, IPTools.ipToNumber('10.0.0.0'));
|
||||
});
|
||||
|
||||
it('should not yield negative values when parsing CIDR ranges at 128.* or higher', () => {
|
||||
assert.equal(IPTools.getCidrRange('173.255.160.0/19').minIP, IPTools.ipToNumber('173.255.160.0'));
|
||||
});
|
||||
|
||||
it('should guess whether a range is CIDR or hyphen', () => {
|
||||
const cidrRange = IPTools.stringToRange('42.42.0.0/18');
|
||||
const stringRange = IPTools.stringToRange('42.42.0.0 - 42.42.63.255');
|
||||
|
||||
Reference in New Issue
Block a user