@optique/core 1.0.0-dev.1442 → 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/message.cjs CHANGED
@@ -67,8 +67,8 @@ function message(message$1, ...values$1) {
67
67
  type: "value",
68
68
  value: value$1
69
69
  });
70
- else if (Array.isArray(value$1)) messageTerms.push(...value$1);
71
- else if (typeof value$1 === "object" && value$1 != null && "type" in value$1) messageTerms.push(value$1);
70
+ else if (Array.isArray(value$1)) messageTerms.push(...cloneMessage(value$1));
71
+ else if (typeof value$1 === "object" && value$1 != null && "type" in value$1) messageTerms.push(cloneMessageTerm(value$1));
72
72
  else throw new TypeError(`Invalid value type in message: ${typeof value$1}.`);
73
73
  }
74
74
  return messageTerms;
package/dist/message.js CHANGED
@@ -66,8 +66,8 @@ function message(message$1, ...values$1) {
66
66
  type: "value",
67
67
  value: value$1
68
68
  });
69
- else if (Array.isArray(value$1)) messageTerms.push(...value$1);
70
- else if (typeof value$1 === "object" && value$1 != null && "type" in value$1) messageTerms.push(value$1);
69
+ else if (Array.isArray(value$1)) messageTerms.push(...cloneMessage(value$1));
70
+ else if (typeof value$1 === "object" && value$1 != null && "type" in value$1) messageTerms.push(cloneMessageTerm(value$1));
71
71
  else throw new TypeError(`Invalid value type in message: ${typeof value$1}.`);
72
72
  }
73
73
  return messageTerms;
@@ -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
  };
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1442+4c1b0441",
3
+ "version": "1.0.0-dev.1451+2c581df8",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",