From 7712e02d2d4a32ee97c28956af3fbc36873c0fe1 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Mon, 23 Nov 2020 10:38:59 +0100 Subject: [PATCH] Don't allow empty custom field values --- .../main/scala/docspell/common/CustomFieldType.scala | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/modules/common/src/main/scala/docspell/common/CustomFieldType.scala b/modules/common/src/main/scala/docspell/common/CustomFieldType.scala index 1505233f..6c217550 100644 --- a/modules/common/src/main/scala/docspell/common/CustomFieldType.scala +++ b/modules/common/src/main/scala/docspell/common/CustomFieldType.scala @@ -28,7 +28,10 @@ object CustomFieldType { value def parseValue(value: String): Either[String, String] = - Right(value) + Option(value) + .map(_.trim) + .filter(_.nonEmpty) + .toRight("Empty values are not allowed.") } case object Numeric extends CustomFieldType { @@ -62,7 +65,11 @@ object CustomFieldType { value.toString def parseValue(value: String): Either[String, Boolean] = - Right(value.equalsIgnoreCase("true")) + Option(value) + .map(_.trim) + .filter(_.nonEmpty) + .toRight("Empty values not allowed") + .map(_.equalsIgnoreCase("true")) }