@optique/core 1.0.0-dev.1163 → 1.0.0-dev.1172

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.
@@ -924,6 +924,8 @@ interface HostnameOptions {
924
924
  * - Labels can contain alphanumeric characters and hyphens
925
925
  * - Labels cannot start or end with a hyphen
926
926
  * - Total length ≤ 253 characters (default)
927
+ * - Dotted all-numeric strings (e.g., `192.168.0.1`) are rejected as they
928
+ * resemble IPv4 addresses rather than DNS hostnames
927
929
  *
928
930
  * @param options - Options for hostname validation.
929
931
  * @returns A value parser for hostnames.
@@ -1128,6 +1128,8 @@ function ipv4(options) {
1128
1128
  * - Labels can contain alphanumeric characters and hyphens
1129
1129
  * - Labels cannot start or end with a hyphen
1130
1130
  * - Total length ≤ 253 characters (default)
1131
+ * - Dotted all-numeric strings (e.g., `192.168.0.1`) are rejected as they
1132
+ * resemble IPv4 addresses rather than DNS hostnames
1131
1133
  *
1132
1134
  * @param options - Options for hostname validation.
1133
1135
  * @returns A value parser for hostnames.
@@ -1168,7 +1170,7 @@ function hostname(options) {
1168
1170
  error: msg
1169
1171
  };
1170
1172
  }
1171
- if (!allowLocalhost && input === "localhost") {
1173
+ if (!allowLocalhost && input.toLowerCase() === "localhost") {
1172
1174
  const errorMsg = options?.errors?.localhostNotAllowed;
1173
1175
  const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? message`Hostname 'localhost' is not allowed.`;
1174
1176
  return {
@@ -1194,6 +1196,14 @@ function hostname(options) {
1194
1196
  error: msg
1195
1197
  };
1196
1198
  }
1199
+ if (!allowLocalhost && rest.toLowerCase() === "localhost") {
1200
+ const errorMsg = options?.errors?.localhostNotAllowed;
1201
+ const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? message`Hostname 'localhost' is not allowed.`;
1202
+ return {
1203
+ success: false,
1204
+ error: msg
1205
+ };
1206
+ }
1197
1207
  }
1198
1208
  if (!allowUnderscore && input.includes("_")) {
1199
1209
  const errorMsg = options?.errors?.underscoreNotAllowed;
@@ -1248,6 +1258,14 @@ function hostname(options) {
1248
1258
  };
1249
1259
  }
1250
1260
  }
1261
+ if (labels.length >= 2 && labels.every((l) => /^[0-9]+$/.test(l))) {
1262
+ const errorMsg = options?.errors?.invalidHostname;
1263
+ const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? message`Expected a valid hostname, but got ${input}.`;
1264
+ return {
1265
+ success: false,
1266
+ error: msg
1267
+ };
1268
+ }
1251
1269
  return {
1252
1270
  success: true,
1253
1271
  value: input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optique/core",
3
- "version": "1.0.0-dev.1163+65b042cd",
3
+ "version": "1.0.0-dev.1172+53faea83",
4
4
  "description": "Type-safe combinatorial command-line interface parser",
5
5
  "keywords": [
6
6
  "CLI",