@optique/core 1.0.0-dev.1448 → 1.0.0-dev.1451
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/valueparser.cjs +34 -1
- package/dist/valueparser.js +34 -1
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -1675,8 +1675,37 @@ function socketAddress(options) {
|
|
|
1675
1675
|
function looksLikeIpv4(input) {
|
|
1676
1676
|
return /^\d+\.\d+\.\d+\.\d+$/.test(input);
|
|
1677
1677
|
}
|
|
1678
|
+
function looksLikeAltIpv4Literal(input) {
|
|
1679
|
+
if (/^0[xX][0-9a-fA-F]+$/.test(input)) {
|
|
1680
|
+
const n = parseInt(input.slice(2), 16);
|
|
1681
|
+
return n <= 4294967295;
|
|
1682
|
+
}
|
|
1683
|
+
if (/^0[0-7]+$/.test(input)) {
|
|
1684
|
+
const n = parseInt(input.slice(1), 8);
|
|
1685
|
+
return n <= 4294967295;
|
|
1686
|
+
}
|
|
1687
|
+
const parts = input.split(".");
|
|
1688
|
+
if (parts.length >= 2 && parts.length <= 4) {
|
|
1689
|
+
const numericOrHex = /^(?:[0-9]+|0[xX][0-9a-fA-F]+)$/;
|
|
1690
|
+
if (parts.every((p) => numericOrHex.test(p)) && parts.some((p) => /^0[xX]/i.test(p) || p.length > 1 && p[0] === "0")) {
|
|
1691
|
+
const values = [];
|
|
1692
|
+
for (const p of parts) if (/^0[xX]/i.test(p)) values.push(parseInt(p.slice(2), 16));
|
|
1693
|
+
else if (p.length > 1 && p[0] === "0") {
|
|
1694
|
+
if (/[89]/.test(p)) return false;
|
|
1695
|
+
values.push(parseInt(p, 8));
|
|
1696
|
+
} else values.push(Number(p));
|
|
1697
|
+
const lastMax = 256 ** (5 - parts.length);
|
|
1698
|
+
return values.slice(0, -1).every((v) => v <= 255) && values[values.length - 1] < lastMax;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1678
1703
|
function parseHost(hostInput) {
|
|
1679
1704
|
if (hostType === "hostname") {
|
|
1705
|
+
if (looksLikeAltIpv4Literal(hostInput)) return {
|
|
1706
|
+
success: false,
|
|
1707
|
+
error: require_message.message`${hostInput} appears to be a non-standard IPv4 address notation.`
|
|
1708
|
+
};
|
|
1680
1709
|
if (looksLikeIpv4(hostInput)) return {
|
|
1681
1710
|
success: false,
|
|
1682
1711
|
error: require_message.message`Expected a valid hostname, but got ${hostInput}.`
|
|
@@ -1684,6 +1713,10 @@ function socketAddress(options) {
|
|
|
1684
1713
|
return hostnameParser.parse(hostInput);
|
|
1685
1714
|
} else if (hostType === "ip") return ipParser.parse(hostInput);
|
|
1686
1715
|
else {
|
|
1716
|
+
if (looksLikeAltIpv4Literal(hostInput)) return {
|
|
1717
|
+
success: false,
|
|
1718
|
+
error: require_message.message`${hostInput} appears to be a non-standard IPv4 address notation.`
|
|
1719
|
+
};
|
|
1687
1720
|
if (looksLikeIpv4(hostInput)) return ipParser.parse(hostInput);
|
|
1688
1721
|
return hostnameParser.parse(hostInput);
|
|
1689
1722
|
}
|
|
@@ -1713,7 +1746,7 @@ function socketAddress(options) {
|
|
|
1713
1746
|
error: msg
|
|
1714
1747
|
};
|
|
1715
1748
|
}
|
|
1716
|
-
if (looksLikeIpv4(hostPart)) return {
|
|
1749
|
+
if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) return {
|
|
1717
1750
|
success: false,
|
|
1718
1751
|
error: hostResult.error
|
|
1719
1752
|
};
|
package/dist/valueparser.js
CHANGED
|
@@ -1675,8 +1675,37 @@ function socketAddress(options) {
|
|
|
1675
1675
|
function looksLikeIpv4(input) {
|
|
1676
1676
|
return /^\d+\.\d+\.\d+\.\d+$/.test(input);
|
|
1677
1677
|
}
|
|
1678
|
+
function looksLikeAltIpv4Literal(input) {
|
|
1679
|
+
if (/^0[xX][0-9a-fA-F]+$/.test(input)) {
|
|
1680
|
+
const n = parseInt(input.slice(2), 16);
|
|
1681
|
+
return n <= 4294967295;
|
|
1682
|
+
}
|
|
1683
|
+
if (/^0[0-7]+$/.test(input)) {
|
|
1684
|
+
const n = parseInt(input.slice(1), 8);
|
|
1685
|
+
return n <= 4294967295;
|
|
1686
|
+
}
|
|
1687
|
+
const parts = input.split(".");
|
|
1688
|
+
if (parts.length >= 2 && parts.length <= 4) {
|
|
1689
|
+
const numericOrHex = /^(?:[0-9]+|0[xX][0-9a-fA-F]+)$/;
|
|
1690
|
+
if (parts.every((p) => numericOrHex.test(p)) && parts.some((p) => /^0[xX]/i.test(p) || p.length > 1 && p[0] === "0")) {
|
|
1691
|
+
const values = [];
|
|
1692
|
+
for (const p of parts) if (/^0[xX]/i.test(p)) values.push(parseInt(p.slice(2), 16));
|
|
1693
|
+
else if (p.length > 1 && p[0] === "0") {
|
|
1694
|
+
if (/[89]/.test(p)) return false;
|
|
1695
|
+
values.push(parseInt(p, 8));
|
|
1696
|
+
} else values.push(Number(p));
|
|
1697
|
+
const lastMax = 256 ** (5 - parts.length);
|
|
1698
|
+
return values.slice(0, -1).every((v) => v <= 255) && values[values.length - 1] < lastMax;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
return false;
|
|
1702
|
+
}
|
|
1678
1703
|
function parseHost(hostInput) {
|
|
1679
1704
|
if (hostType === "hostname") {
|
|
1705
|
+
if (looksLikeAltIpv4Literal(hostInput)) return {
|
|
1706
|
+
success: false,
|
|
1707
|
+
error: message`${hostInput} appears to be a non-standard IPv4 address notation.`
|
|
1708
|
+
};
|
|
1680
1709
|
if (looksLikeIpv4(hostInput)) return {
|
|
1681
1710
|
success: false,
|
|
1682
1711
|
error: message`Expected a valid hostname, but got ${hostInput}.`
|
|
@@ -1684,6 +1713,10 @@ function socketAddress(options) {
|
|
|
1684
1713
|
return hostnameParser.parse(hostInput);
|
|
1685
1714
|
} else if (hostType === "ip") return ipParser.parse(hostInput);
|
|
1686
1715
|
else {
|
|
1716
|
+
if (looksLikeAltIpv4Literal(hostInput)) return {
|
|
1717
|
+
success: false,
|
|
1718
|
+
error: message`${hostInput} appears to be a non-standard IPv4 address notation.`
|
|
1719
|
+
};
|
|
1687
1720
|
if (looksLikeIpv4(hostInput)) return ipParser.parse(hostInput);
|
|
1688
1721
|
return hostnameParser.parse(hostInput);
|
|
1689
1722
|
}
|
|
@@ -1713,7 +1746,7 @@ function socketAddress(options) {
|
|
|
1713
1746
|
error: msg
|
|
1714
1747
|
};
|
|
1715
1748
|
}
|
|
1716
|
-
if (looksLikeIpv4(hostPart)) return {
|
|
1749
|
+
if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) return {
|
|
1717
1750
|
success: false,
|
|
1718
1751
|
error: hostResult.error
|
|
1719
1752
|
};
|