mirror of
https://github.com/gosticks/web.git
synced 2026-10-06 06:37:07 +00:00
Make sure IPv4 addresses can not contain segments greater than 255
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
+3
-4
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user