Implemented replacing diacritics and reserved XML characters in SEPA messages

This commit is contained in:
dankito 2020-05-14 00:52:54 +02:00
parent fc94b47fca
commit e18ffb8a83
3 changed files with 46 additions and 5 deletions

View File

@ -20,7 +20,7 @@ import java.util.regex.Pattern
open class SepaMessageCreator : ISepaMessageCreator { open class SepaMessageCreator : ISepaMessageCreator {
companion object { companion object {
const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" " const val AllowedSepaCharacters = "A-Za-z0-9\\?,\\-\\+\\.,:/\\(\\)\'\" (&\\w{2,4};)"
val AllowedSepaCharactersPattern: Pattern = Pattern.compile("^[$AllowedSepaCharacters]*$") val AllowedSepaCharactersPattern: Pattern = Pattern.compile("^[$AllowedSepaCharacters]*$")
@ -39,7 +39,9 @@ open class SepaMessageCreator : ISepaMessageCreator {
override fun containsOnlyAllowedCharacters(stringToTest: String): Boolean { override fun containsOnlyAllowedCharacters(stringToTest: String): Boolean {
return AllowedSepaCharactersPattern.matcher(stringToTest).matches() val convertedString = convertToAllowedCharacters(stringToTest)
return AllowedSepaCharactersPattern.matcher(convertedString).matches()
} }
override fun convertToAllowedCharacters(input: String): String { override fun convertToAllowedCharacters(input: String): String {
@ -50,6 +52,41 @@ open class SepaMessageCreator : ISepaMessageCreator {
.replace("&", "&") .replace("&", "&")
.replace("<", "&lt;") .replace("<", "&lt;")
.replace(">", "&gt;") .replace(">", "&gt;")
// convert diacritics
.replace("á", "a", true)
.replace("à", "a", true)
.replace("â", "a", true)
.replace("ã", "a", true)
.replace("ä", "a", true)
.replace("å", "a", true)
.replace("é", "e", true)
.replace("è", "e", true)
.replace("ê", "e", true)
.replace("ë", "e", true)
.replace("í", "i", true)
.replace("ì", "i", true)
.replace("î", "i", true)
.replace("ï", "i", true)
.replace("ó", "o", true)
.replace("ò", "o", true)
.replace("ô", "o", true)
.replace("õ", "o", true)
.replace("ö", "o", true)
.replace("ú", "u", true)
.replace("ù", "u", true)
.replace("û", "u", true)
.replace("ũ", "u", true)
.replace("ü", "u", true)
.replace("ç", "u", true)
.replace("č", "u", true)
.replace("ñ", "u", true)
.replace("ß", "ss", true)
} }

View File

@ -232,11 +232,11 @@ open class TransferMoneyDialog : DialogFragment() {
protected open fun transferMoney() { protected open fun transferMoney() {
getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered
val data = TransferMoneyData( val data = TransferMoneyData(
edtxtRemitteeName.text.toString(), inputValidator.convertToAllowedSepaCharacters(edtxtRemitteeName.text.toString()),
edtxtRemitteeIban.text.toString().replace(" ", ""), edtxtRemitteeIban.text.toString().replace(" ", ""),
edtxtRemitteeBic.text.toString().replace(" ", ""), edtxtRemitteeBic.text.toString().replace(" ", ""),
amount, amount,
edtxtUsage.text.toString(), inputValidator.convertToAllowedSepaCharacters(edtxtUsage.text.toString()),
chkbxInstantPayment.isChecked chkbxInstantPayment.isChecked
) )

View File

@ -78,7 +78,11 @@ open class InputValidator {
} }
open fun getInvalidSepaCharacters(string: String): String { open fun getInvalidSepaCharacters(string: String): String {
return getInvalidCharacters(string, InvalidSepaCharactersPattern) return getInvalidCharacters(convertToAllowedSepaCharacters(string), InvalidSepaCharactersPattern)
}
open fun convertToAllowedSepaCharacters(string: String): String {
return sepaMessageCreator.convertToAllowedCharacters(string)
} }