bugfix/adding checkOptionalShortString and using in CreateBank v5.1.0

This commit is contained in:
simonredfern 2025-09-10 13:08:00 +02:00
parent 8143f6449a
commit d275ec71a2
2 changed files with 13 additions and 1 deletions

View File

@ -911,6 +911,18 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
}
}
/** only A-Z, a-z, 0-9, -, _, ., and max length <= 16, allows empty string */
def checkOptionalShortString(value:String): String ={
val valueLength = value.length
val regex = """^([A-Za-z0-9\-._]*)$""".r
value match {
case regex(e) if(valueLength <= 16) => SILENCE_IS_GOLDEN
case regex(e) if(valueLength > 16) => ErrorMessages.InvalidValueLength
case _ => ErrorMessages.InvalidValueCharacters
}
}
/** only A-Z, a-z, 0-9, -, _, ., and max length <= 36
* OBP APIUtil.generateUUID() length is 36 here.*/

View File

@ -182,7 +182,7 @@ trait APIMethods500 {
}
//if postJson.id is empty, just return SILENCE_IS_GOLDEN, and will pass the guard.
checkShortStringValue = APIUtil.checkShortString(postJson.id.getOrElse(SILENCE_IS_GOLDEN))
checkShortStringValue = APIUtil.checkOptionalShortString(postJson.id.getOrElse(SILENCE_IS_GOLDEN))
_ <- Helper.booleanToFuture(failMsg = s"$checkShortStringValue.", cc = cc.callContext) {
checkShortStringValue == SILENCE_IS_GOLDEN
}