mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-24 23:10:13 +08:00
fix(ui): incorrect regexp to determine whether is a domain name
This commit is contained in:
@@ -3,7 +3,7 @@ import { Form, Input, InputNumber, Select } from "antd";
|
||||
import { createSchemaFieldRule } from "antd-zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import { isDomain, isIPv4, isIPv6, isPortNumber } from "@/utils/validator";
|
||||
import { isHostname, isPortNumber } from "@/utils/validator";
|
||||
|
||||
import { useFormNestedFieldsContext } from "./_context";
|
||||
|
||||
@@ -81,7 +81,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
|
||||
const { t } = i18n;
|
||||
|
||||
return z.object({
|
||||
host: z.string().refine((v) => isDomain(v) || isIPv4(v) || isIPv6(v), t("common.errmsg.host_invalid")),
|
||||
host: z.string().refine((v) => isHostname(v), t("common.errmsg.host_invalid")),
|
||||
port: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")),
|
||||
tsigAlgorithm: z.string().nonempty(t("access.form.rfc2136_tsig_algorithm.placeholder")),
|
||||
tsigKey: z.string().nullish(),
|
||||
|
||||
@@ -7,7 +7,7 @@ import { z } from "zod";
|
||||
import FileTextInput from "@/components/FileTextInput";
|
||||
import Show from "@/components/Show";
|
||||
import { mergeCls } from "@/utils/css";
|
||||
import { isDomain, isIPv4, isIPv6, isPortNumber } from "@/utils/validator";
|
||||
import { isHostname, isPortNumber } from "@/utils/validator";
|
||||
|
||||
import { useFormNestedFieldsContext } from "./_context";
|
||||
|
||||
@@ -234,7 +234,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
|
||||
|
||||
const baseSchema = z
|
||||
.object({
|
||||
host: z.string().refine((v) => isDomain(v) || isIPv4(v) || isIPv6(v), t("common.errmsg.host_invalid")),
|
||||
host: z.string().refine((v) => isHostname(v), t("common.errmsg.host_invalid")),
|
||||
port: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")),
|
||||
authMethod: z.literal([AUTH_METHOD_NONE, AUTH_METHOD_PASSWORD, AUTH_METHOD_KEY], t("access.form.ssh_auth_method.placeholder")),
|
||||
username: z.string().nonempty(t("access.form.ssh_username.placeholder")),
|
||||
|
||||
@@ -25,7 +25,7 @@ import { useAccessesStore } from "@/stores/access";
|
||||
import { useContactEmailsStore } from "@/stores/settings";
|
||||
import { getErrMsg } from "@/utils/error";
|
||||
import { matchSearchOption } from "@/utils/search";
|
||||
import { isDomain, isIPv4, isIPv6 } from "@/utils/validator";
|
||||
import { isDomain, isHostname } from "@/utils/validator";
|
||||
|
||||
import { FormNestedFieldsContextProvider, NodeFormContextProvider } from "./_context";
|
||||
import BizApplyNodeConfigFieldsProvider from "./BizApplyNodeConfigFieldsProvider";
|
||||
@@ -886,7 +886,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
|
||||
|
||||
return String(v)
|
||||
.split(MULTIPLE_INPUT_SEPARATOR)
|
||||
.every((e) => isIPv4(e) || isIPv6(e) || isDomain(e));
|
||||
.every((e) => isHostname(e) || isDomain(e));
|
||||
}, t("common.errmsg.host_invalid")),
|
||||
dnsPropagationWait: z.preprocess(
|
||||
(v) => (v == null || v === "" ? void 0 : Number(v)),
|
||||
|
||||
@@ -8,7 +8,7 @@ import { z } from "zod";
|
||||
import Tips from "@/components/Tips";
|
||||
import { type WorkflowNodeConfigForBizMonitor, defaultNodeConfigForBizMonitor } from "@/domain/workflow";
|
||||
import { useAntdForm } from "@/hooks";
|
||||
import { isDomain, isIPv4, isIPv6, isPortNumber } from "@/utils/validator";
|
||||
import { isDomain, isHostname, isPortNumber } from "@/utils/validator";
|
||||
|
||||
import { NodeFormContextProvider } from "./_context";
|
||||
import { NodeType } from "../nodes/typings";
|
||||
@@ -90,7 +90,7 @@ const getSchema = ({ i18n = getI18n() }: { i18n?: ReturnType<typeof getI18n> })
|
||||
const { t } = i18n;
|
||||
|
||||
return z.object({
|
||||
host: z.string().refine((v) => isDomain(v) || isIPv4(v) || isIPv6(v), t("common.errmsg.host_invalid")),
|
||||
host: z.string().refine((v) => isHostname(v), t("common.errmsg.host_invalid")),
|
||||
port: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")),
|
||||
domain: z
|
||||
.string()
|
||||
|
||||
@@ -8,8 +8,8 @@ export const isCron = (value: string) => {
|
||||
|
||||
export const isDomain = (value: string, { allowWildcard = false }: { allowWildcard?: boolean } = {}) => {
|
||||
const re = allowWildcard
|
||||
? /^(?:\*\.)?(?!-)[A-Za-z0-9-]{1,}(?<!-)(\.[A-Za-z0-9-]{1,}(?<!-)){0,}$/
|
||||
: /^(?!-)[A-Za-z0-9-]{1,}(?<!-)(\.[A-Za-z0-9-]{1,}(?<!-)){0,}$/;
|
||||
? /^(?:\*\.)?(?!-)[A-Za-z0-9-]{1,}(?<!-)(\.[A-Za-z0-9-]{1,}(?<!-)){0,}(?<![-0-9])$/
|
||||
: /^(?!-)[A-Za-z0-9-]{1,}(?<!-)(\.[A-Za-z0-9-]{1,}(?<!-)){0,}(?<![-0-9])$/;
|
||||
return re.test(value);
|
||||
};
|
||||
|
||||
@@ -17,6 +17,10 @@ export const isEmail = (value: string) => {
|
||||
return z.email().safeParse(value).success;
|
||||
};
|
||||
|
||||
export const isHostname = (value: string) => {
|
||||
return isDomain(value, { allowWildcard: false }) || isIPv4(value) || isIPv6(value);
|
||||
};
|
||||
|
||||
export const isIPv4 = (value: string) => {
|
||||
return z.ipv4().safeParse(value).success;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user