fix: Server error with invalid Prosemirror JSON should be validation error

This commit is contained in:
Tom Moor
2023-07-15 23:04:30 -04:00
parent e81f97b2de
commit abb38ea447

View File

@@ -22,10 +22,16 @@ export default function TextLength({
addAttributeOptions(target, propertyName, {
validate: {
validLength(value: ProsemirrorData) {
const text = ProsemirrorHelper.toPlainText(
Node.fromJSON(schema, value),
schema
);
let text;
try {
text = ProsemirrorHelper.toPlainText(
Node.fromJSON(schema, value),
schema
);
} catch (err) {
throw new Error("Invalid data");
}
if (size(text) > max || size(text) < min) {
throw new Error(msg);