Make sure IPv4 addresses can not contain segments greater than 255

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
Mcat12
2018-11-05 12:59:52 -05:00
parent 1895b106ff
commit 7d64bb33f8
2 changed files with 7 additions and 4 deletions
+3 -4
View File
@@ -66,10 +66,9 @@ export function isValidIpv4(address) {
}
// No segment can be longer than 3 characters or be empty
if (segments.some(segment => segment.length > 3 || segment.length === 0)) {
return false;
}
// All segments must be numbers (positive)
return segments.every(segment => isPositiveNumber(segment));
return segments.every(
segment => isPositiveNumber(segment) && parseInt(segment) < 256
);
}
+4
View File
@@ -183,5 +183,9 @@ describe("Testing the validation functions", () => {
it("fails 10. 10.1.1", () => {
expect(isValidIpv4("10. 10.1.1")).toBe(false);
});
it("fails 555.666.777.888", () => {
expect(isValidIpv4("555.666.777.888")).toBe(false);
});
});
});