mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-18 06:58:36 +00:00
29 lines
822 B
TypeScript
29 lines
822 B
TypeScript
import safe from "safe-regex";
|
|
import z from "zod";
|
|
|
|
import { CharacterType, characterValidator } from "@app/lib/validator/validate-string";
|
|
|
|
export const validateTemplateRegexField = z
|
|
.string()
|
|
.min(1)
|
|
.max(100)
|
|
.refine(
|
|
(val) =>
|
|
characterValidator([
|
|
CharacterType.AlphaNumeric,
|
|
CharacterType.Spaces, // (space)
|
|
CharacterType.Asterisk, // *
|
|
CharacterType.At, // @
|
|
CharacterType.Hyphen, // -
|
|
CharacterType.Period, // .
|
|
CharacterType.Backslash // \
|
|
])(val),
|
|
{
|
|
message: "Invalid pattern: only alphanumeric characters, spaces, *, ., @, -, and \\ are allowed."
|
|
}
|
|
)
|
|
// we ensure that the inputted pattern is computationally safe by limiting star height to 1
|
|
.refine((v) => safe(v), {
|
|
message: "Unsafe REGEX pattern"
|
|
});
|