test both max length and pattern if declared

This commit is contained in:
Hongbo Wu
2022-04-13 12:20:41 +08:00
parent 928ddd69a9
commit 3b831fecb8

View File

@ -25,7 +25,8 @@ export class SanitizedString extends GraphQLScalarType {
throw new Error(
`Specified value cannot be longer than ${maxLength} characters`
)
} else if (pattern && !pattern.test(value)) {
}
if (pattern && !pattern.test(value)) {
throw new Error(`Specified value does not match pattern`)
}
return sanitize(value, { allowedTags: allowedTags || [] })
@ -38,7 +39,8 @@ export class SanitizedString extends GraphQLScalarType {
throw new Error(
`Specified value cannot be longer than ${maxLength} characters`
)
} else if (pattern && !pattern.test(value)) {
}
if (pattern && !pattern.test(value)) {
throw new Error(`Specified value does not match pattern`)
}
return sanitize(value, { allowedTags: allowedTags || [] })