Skip to content

Commit

Permalink
variable for trimmed string
Browse files Browse the repository at this point in the history
  • Loading branch information
js-jankisalvi committed Jun 30, 2023
1 parent 943da11 commit dfcb2be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/cases/common/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ export const limitedStringSchema = (fieldName: string, min: number, max: number)
rt.string.is,
(input, context) =>
either.chain(rt.string.validate(input, context), (s) => {
if (s.trim().length === 0 && s.trim().length < min) {
const trimmedString = s.trim();

if (trimmedString.length === 0 && trimmedString.length < min) {
return rt.failure(input, context, `The ${fieldName} field cannot be an empty string.`);
}

if (s.trim().length < min) {
if (trimmedString.length < min) {
return rt.failure(
input,
context,
`The length of the ${fieldName} is too short. The minimum length is ${min}.`
);
}

if (s.trim().length > max) {
if (trimmedString.length > max) {
return rt.failure(
input,
context,
Expand Down

0 comments on commit dfcb2be

Please sign in to comment.