MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / parseIpv4

Function parseIpv4

packages/core/sdk/src/hosted-http-client.ts:43–54  ·  view source on GitHub ↗
(hostname: string)

Source from the content-addressed store, hash-verified

41// these forms, so the URL path never produces one, but a resolver answer
42// reaches isAllowedResolvedAddress unnormalized.
43const parseIpv4 = (hostname: string): readonly [number, number, number, number] | null => {
44 const parts = hostname.split(".");
45 if (parts.length !== 4) return null;
46 const parsed: number[] = [];
47 for (const part of parts) {
48 if (!/^(?:0|[1-9]\d*)$/.test(part)) return null;
49 const value = Number(part);
50 if (!Number.isInteger(value) || value < 0 || value > 255) return null;
51 parsed.push(value);
52 }
53 return parsed as [number, number, number, number];
54};
55
56// `allowTrailingQuad` is the caller's statement that this segment ends the
57// whole address, not merely that it ends its own half. Deciding it from the

Callers 5

parseIpv6GroupsFunction · 0.85
isBlockedMetadataAddressFunction · 0.85
isLocalOrPrivateHostnameFunction · 0.85
isAllowedResolvedAddressFunction · 0.85
isAddressLiteralFunction · 0.85

Calls 1

pushMethod · 0.80

Tested by

no test coverage detected