mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 04:18:54 +00:00
feat: special ip address 'localhost' (#2935)
This commit is contained in:
@@ -4,9 +4,11 @@ import { isValidIPAddress } from '../is-valid-ip-address';
|
||||
|
||||
describe('isValidIpAddress', () => {
|
||||
test('should return true for valid IP address', () => {
|
||||
['115.42.150.37', '192.168.0.1', '110.234.52.124'].forEach(ip => {
|
||||
expect(isValidIPAddress(ip)).toBe(true);
|
||||
});
|
||||
['115.42.150.37', '192.168.0.1', '110.234.52.124', 'localhost'].forEach(
|
||||
ip => {
|
||||
expect(isValidIPAddress(ip)).toBe(true);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test('should return false for invalid IP address', () => {
|
||||
|
||||
3
packages/env/src/is-valid-ip-address.ts
vendored
3
packages/env/src/is-valid-ip-address.ts
vendored
@@ -1,4 +1,7 @@
|
||||
export function isValidIPAddress(address: string) {
|
||||
if (address === 'localhost') {
|
||||
return true;
|
||||
}
|
||||
return /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(
|
||||
address
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user