@optique/core 1.0.0-dev.1448 → 1.0.0-dev.1452

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
@@ -106,7 +106,7 @@ function optionName(name) {
106
106
  function optionNames(names) {
107
107
  return {
108
108
  type: "optionNames",
109
- optionNames: names
109
+ optionNames: [...names]
110
110
  };
111
111
  }
112
112
  /**
@@ -147,7 +147,7 @@ function value(value$1) {
147
147
  function values(values$1) {
148
148
  return {
149
149
  type: "values",
150
- values: values$1
150
+ values: [...values$1]
151
151
  };
152
152
  }
153
153
  /**
@@ -203,7 +203,7 @@ function url(url$1) {
203
203
  if (typeof url$1 === "string") {
204
204
  if (!URL.canParse(url$1)) throw new RangeError(`Invalid URL: ${url$1}.`);
205
205
  urlObj = new URL(url$1);
206
- } else urlObj = url$1;
206
+ } else urlObj = new URL(url$1.href);
207
207
  return {
208
208
  type: "url",
209
209
  url: urlObj
package/dist/message.js CHANGED
@@ -105,7 +105,7 @@ function optionName(name) {
105
105
  function optionNames(names) {
106
106
  return {
107
107
  type: "optionNames",
108
- optionNames: names
108
+ optionNames: [...names]
109
109
  };
110
110
  }
111
111
  /**
@@ -146,7 +146,7 @@ function value(value$1) {
146
146
  function values(values$1) {
147
147
  return {
148
148
  type: "values",
149
- values: values$1
149
+ values: [...values$1]
150
150
  };
151
151
  }
152
152
  /**
@@ -202,7 +202,7 @@ function url(url$1) {
202
202
  if (typeof url$1 === "string") {
203
203
  if (!URL.canParse(url$1)) throw new RangeError(`Invalid URL: ${url$1}.`);
204
204
  urlObj = new URL(url$1);
205
- } else urlObj = url$1;
205
+ } else urlObj = new URL(url$1.href);
206
206
  return {
207
207
  type: "url",
208
208
  url: urlObj
@@ -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.1448+eeae0552",
3
+ "version": "1.0.0-dev.1452+b060cbd3",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",