@optique/core 1.0.0-dev.1596 → 1.0.0-dev.1598

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.
@@ -1745,21 +1745,24 @@ function socketAddress(options) {
1745
1745
  },
1746
1746
  parse(input) {
1747
1747
  const trimmed = input.trim();
1748
+ const searchInput = input.trimStart();
1748
1749
  const canOmitPort = defaultPort !== void 0 && !requirePort;
1749
1750
  let firstHostError;
1750
1751
  let validHostInvalidPortError;
1751
1752
  let trailingSepHost;
1752
1753
  let trailingSepHostError;
1753
1754
  let anySeparatorFound = false;
1754
- let searchFrom = trimmed.length;
1755
+ let trailingSepInTrimmedRegion = false;
1756
+ let searchFrom = searchInput.length;
1755
1757
  while (searchFrom > 0) {
1756
- const separatorIndex = trimmed.lastIndexOf(separator, searchFrom - 1);
1758
+ const separatorIndex = searchInput.lastIndexOf(separator, searchFrom - 1);
1757
1759
  if (separatorIndex === -1) break;
1758
1760
  anySeparatorFound = true;
1759
- const hostPart = trimmed.substring(0, separatorIndex);
1760
- const portPart = trimmed.substring(separatorIndex + separator.length);
1761
+ const hostPart = searchInput.substring(0, separatorIndex).trim();
1762
+ const portPart = searchInput.substring(separatorIndex + separator.length).trim();
1761
1763
  if (portPart === "") {
1762
1764
  if (trailingSepHost === void 0 && trailingSepHostError === void 0) {
1765
+ if (separatorIndex + separator.length > trimmed.length) trailingSepInTrimmedRegion = true;
1763
1766
  const hostResult = parseHost(hostPart);
1764
1767
  if (hostResult.success) trailingSepHost = hostResult.value;
1765
1768
  else trailingSepHostError = {
@@ -1856,7 +1859,7 @@ function socketAddress(options) {
1856
1859
  let hostOnlyResult;
1857
1860
  if (!requirePort || trailingSepHost !== void 0 || trailingSepHostError !== void 0) {
1858
1861
  hostOnlyResult = parseHost(trimmed);
1859
- if (canOmitPort && hostOnlyResult.success) return {
1862
+ if (canOmitPort && hostOnlyResult.success && !trailingSepInTrimmedRegion) return {
1860
1863
  success: true,
1861
1864
  value: {
1862
1865
  host: hostOnlyResult.value,
@@ -1864,14 +1867,7 @@ function socketAddress(options) {
1864
1867
  }
1865
1868
  };
1866
1869
  }
1867
- if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
1868
- if (canOmitPort) return {
1869
- success: true,
1870
- value: {
1871
- host: trailingSepHost,
1872
- port: defaultPort
1873
- }
1874
- };
1870
+ if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && (!hostOnlyResult.success || trailingSepInTrimmedRegion)) {
1875
1871
  const errorMsg$1 = options?.errors?.missingPort;
1876
1872
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? require_message.message`Port number is required but was not specified.`;
1877
1873
  return {
@@ -1879,7 +1875,7 @@ function socketAddress(options) {
1879
1875
  error: msg
1880
1876
  };
1881
1877
  }
1882
- if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
1878
+ if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && (!hostOnlyResult.success || trailingSepInTrimmedRegion)) {
1883
1879
  const errorMsg$1 = options?.errors?.invalidFormat;
1884
1880
  if (errorMsg$1) {
1885
1881
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
@@ -1745,21 +1745,24 @@ function socketAddress(options) {
1745
1745
  },
1746
1746
  parse(input) {
1747
1747
  const trimmed = input.trim();
1748
+ const searchInput = input.trimStart();
1748
1749
  const canOmitPort = defaultPort !== void 0 && !requirePort;
1749
1750
  let firstHostError;
1750
1751
  let validHostInvalidPortError;
1751
1752
  let trailingSepHost;
1752
1753
  let trailingSepHostError;
1753
1754
  let anySeparatorFound = false;
1754
- let searchFrom = trimmed.length;
1755
+ let trailingSepInTrimmedRegion = false;
1756
+ let searchFrom = searchInput.length;
1755
1757
  while (searchFrom > 0) {
1756
- const separatorIndex = trimmed.lastIndexOf(separator, searchFrom - 1);
1758
+ const separatorIndex = searchInput.lastIndexOf(separator, searchFrom - 1);
1757
1759
  if (separatorIndex === -1) break;
1758
1760
  anySeparatorFound = true;
1759
- const hostPart = trimmed.substring(0, separatorIndex);
1760
- const portPart = trimmed.substring(separatorIndex + separator.length);
1761
+ const hostPart = searchInput.substring(0, separatorIndex).trim();
1762
+ const portPart = searchInput.substring(separatorIndex + separator.length).trim();
1761
1763
  if (portPart === "") {
1762
1764
  if (trailingSepHost === void 0 && trailingSepHostError === void 0) {
1765
+ if (separatorIndex + separator.length > trimmed.length) trailingSepInTrimmedRegion = true;
1763
1766
  const hostResult = parseHost(hostPart);
1764
1767
  if (hostResult.success) trailingSepHost = hostResult.value;
1765
1768
  else trailingSepHostError = {
@@ -1856,7 +1859,7 @@ function socketAddress(options) {
1856
1859
  let hostOnlyResult;
1857
1860
  if (!requirePort || trailingSepHost !== void 0 || trailingSepHostError !== void 0) {
1858
1861
  hostOnlyResult = parseHost(trimmed);
1859
- if (canOmitPort && hostOnlyResult.success) return {
1862
+ if (canOmitPort && hostOnlyResult.success && !trailingSepInTrimmedRegion) return {
1860
1863
  success: true,
1861
1864
  value: {
1862
1865
  host: hostOnlyResult.value,
@@ -1864,14 +1867,7 @@ function socketAddress(options) {
1864
1867
  }
1865
1868
  };
1866
1869
  }
1867
- if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
1868
- if (canOmitPort) return {
1869
- success: true,
1870
- value: {
1871
- host: trailingSepHost,
1872
- port: defaultPort
1873
- }
1874
- };
1870
+ if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && (!hostOnlyResult.success || trailingSepInTrimmedRegion)) {
1875
1871
  const errorMsg$1 = options?.errors?.missingPort;
1876
1872
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? message`Port number is required but was not specified.`;
1877
1873
  return {
@@ -1879,7 +1875,7 @@ function socketAddress(options) {
1879
1875
  error: msg
1880
1876
  };
1881
1877
  }
1882
- if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
1878
+ if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && (!hostOnlyResult.success || trailingSepInTrimmedRegion)) {
1883
1879
  const errorMsg$1 = options?.errors?.invalidFormat;
1884
1880
  if (errorMsg$1) {
1885
1881
  const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1596+91310a38",
3
+ "version": "1.0.0-dev.1598+6650da3a",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",