Fixed that reserved XML characters aren't replaced visibly to user - XML entities would just confuse most users. But XML entities are taking into calculation for max length
This commit is contained in:
parent
97e7d44a47
commit
318266db0f
|
@ -7,6 +7,8 @@ interface ISepaMessageCreator {
|
||||||
|
|
||||||
fun containsOnlyAllowedCharacters(stringToTest: String): Boolean
|
fun containsOnlyAllowedCharacters(stringToTest: String): Boolean
|
||||||
|
|
||||||
|
fun containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest: String): Boolean
|
||||||
|
|
||||||
fun convertDiacriticsAndReservedXmlCharacters(input: String): String {
|
fun convertDiacriticsAndReservedXmlCharacters(input: String): String {
|
||||||
var converted = convertDiacritics(input)
|
var converted = convertDiacritics(input)
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,12 @@ open class SepaMessageCreator : ISepaMessageCreator {
|
||||||
companion object {
|
companion object {
|
||||||
const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" (&\\w{2,4};)"
|
const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" (&\\w{2,4};)"
|
||||||
|
|
||||||
|
const val ReservedXmlCharacters = "\'\"&<>"
|
||||||
|
|
||||||
val AllowedSepaCharactersPattern = Regex("^[$AllowedSepaCharacters]*$")
|
val AllowedSepaCharactersPattern = Regex("^[$AllowedSepaCharacters]*$")
|
||||||
|
|
||||||
|
val AllowedSepaCharactersExceptReservedXmlCharactersPattern = Regex("^[$AllowedSepaCharacters$ReservedXmlCharacters]*$")
|
||||||
|
|
||||||
const val MessageIdKey = "MessageId"
|
const val MessageIdKey = "MessageId"
|
||||||
|
|
||||||
const val CreationDateTimeKey = "CreationDateTime"
|
const val CreationDateTimeKey = "CreationDateTime"
|
||||||
|
@ -37,6 +41,11 @@ open class SepaMessageCreator : ISepaMessageCreator {
|
||||||
&& convertDiacriticsAndReservedXmlCharacters(stringToTest) == stringToTest
|
&& convertDiacriticsAndReservedXmlCharacters(stringToTest) == stringToTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest: String): Boolean {
|
||||||
|
return AllowedSepaCharactersExceptReservedXmlCharactersPattern.matches(stringToTest)
|
||||||
|
&& convertDiacritics(stringToTest) == stringToTest
|
||||||
|
}
|
||||||
|
|
||||||
override fun convertReservedXmlCharacters(input: String): String {
|
override fun convertReservedXmlCharacters(input: String): String {
|
||||||
// TODO: add other replacement strings
|
// TODO: add other replacement strings
|
||||||
return input
|
return input
|
||||||
|
|
|
@ -58,7 +58,7 @@ open class InputValidator {
|
||||||
val InvalidBicCharactersPattern = Regex("[^A-Z0-9]")
|
val InvalidBicCharactersPattern = Regex("[^A-Z0-9]")
|
||||||
|
|
||||||
|
|
||||||
val InvalidSepaCharactersPattern = Regex("[^${SepaMessageCreator.AllowedSepaCharacters}]+")
|
val InvalidSepaCharactersPattern = Regex("[^${SepaMessageCreator.AllowedSepaCharactersExceptReservedXmlCharactersPattern}]+")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,11 +99,11 @@ open class InputValidator {
|
||||||
|
|
||||||
open fun isRecipientNameValid(stringToTest: String): Boolean {
|
open fun isRecipientNameValid(stringToTest: String): Boolean {
|
||||||
return hasRecipientNameValidLength(stringToTest)
|
return hasRecipientNameValidLength(stringToTest)
|
||||||
&& containsOnlyValidSepaCharacters(stringToTest)
|
&& containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun hasRecipientNameValidLength(stringToTest: String): Boolean {
|
open fun hasRecipientNameValidLength(stringToTest: String): Boolean {
|
||||||
return stringToTest.length in 1..RecipientNameMaxLength
|
return convertToAllowedSepaCharacters(stringToTest).length in 1..RecipientNameMaxLength
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -239,16 +239,16 @@ open class InputValidator {
|
||||||
|
|
||||||
open fun isReferenceValid(stringToTest: String): Boolean {
|
open fun isReferenceValid(stringToTest: String): Boolean {
|
||||||
return hasReferenceValidLength(stringToTest)
|
return hasReferenceValidLength(stringToTest)
|
||||||
&& containsOnlyValidSepaCharacters(stringToTest)
|
&& containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun hasReferenceValidLength(stringToTest: String): Boolean {
|
open fun hasReferenceValidLength(stringToTest: String): Boolean {
|
||||||
return stringToTest.length in 0..ReferenceMaxLength // reference is not a required field -> may be empty
|
return convertToAllowedSepaCharacters(stringToTest).length in 0..ReferenceMaxLength // reference is not a required field -> may be empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open fun containsOnlyValidSepaCharacters(stringToTest: String): Boolean {
|
open fun containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest: String): Boolean {
|
||||||
return sepaMessageCreator.containsOnlyAllowedCharacters(stringToTest)
|
return sepaMessageCreator.containsOnlyAllowedCharactersExceptReservedXmlCharacters(stringToTest)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getInvalidSepaCharacters(string: String): String {
|
open fun getInvalidSepaCharacters(string: String): String {
|
||||||
|
@ -267,7 +267,7 @@ open class InputValidator {
|
||||||
// TODO: do not convert XML entities in user's. User will a) not understand what happened and b) afterwards auto correction will not work anymore (i think the issue lies in used Regex: '(&\w{2,4};)').
|
// TODO: do not convert XML entities in user's. User will a) not understand what happened and b) afterwards auto correction will not work anymore (i think the issue lies in used Regex: '(&\w{2,4};)').
|
||||||
// But take converted XML entities length into account when checking if recipient's name and reference length isn't too long
|
// But take converted XML entities length into account when checking if recipient's name and reference length isn't too long
|
||||||
protected open fun getCorrectedString(inputString: String, invalidCharacters: String, convertToAllowedSepaCharacters: Boolean = false): String {
|
protected open fun getCorrectedString(inputString: String, invalidCharacters: String, convertToAllowedSepaCharacters: Boolean = false): String {
|
||||||
var correctedString = if (convertToAllowedSepaCharacters) convertToAllowedSepaCharacters(inputString) else inputString
|
var correctedString = if (convertToAllowedSepaCharacters) sepaMessageCreator.convertDiacritics(inputString) else inputString
|
||||||
|
|
||||||
invalidCharacters.forEach { invalidChar ->
|
invalidCharacters.forEach { invalidChar ->
|
||||||
correctedString = correctedString.replace(invalidChar.toString(), "")
|
correctedString = correctedString.replace(invalidChar.toString(), "")
|
||||||
|
|
Loading…
Reference in New Issue