From e18ffb8a83ab0a657ec88fe1f70b33d46e76d076 Mon Sep 17 00:00:00 2001 From: dankito Date: Thu, 14 May 2020 00:52:54 +0200 Subject: [PATCH] Implemented replacing diacritics and reserved XML characters in SEPA messages --- .../implementierte/sepa/SepaMessageCreator.kt | 41 ++++++++++++++++++- .../android/ui/dialogs/TransferMoneyDialog.kt | 4 +- .../dankito/banking/util/InputValidator.kt | 6 ++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/fints4k/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt b/fints4k/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt index 013d0ead..bb9df510 100644 --- a/fints4k/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt +++ b/fints4k/src/main/kotlin/net/dankito/fints/messages/segmente/implementierte/sepa/SepaMessageCreator.kt @@ -20,7 +20,7 @@ import java.util.regex.Pattern open class SepaMessageCreator : ISepaMessageCreator { 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]*$") @@ -39,7 +39,9 @@ open class SepaMessageCreator : ISepaMessageCreator { 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 { @@ -50,6 +52,41 @@ open class SepaMessageCreator : ISepaMessageCreator { .replace("&", "&") .replace("<", "<") .replace(">", ">") + + // 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) } diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt index 6eead0df..d8ccfe02 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/fints4java/android/ui/dialogs/TransferMoneyDialog.kt @@ -232,11 +232,11 @@ open class TransferMoneyDialog : DialogFragment() { protected open fun transferMoney() { getEnteredAmount()?.let { amount -> // should only come at this stage when a valid amount has been entered val data = TransferMoneyData( - edtxtRemitteeName.text.toString(), + inputValidator.convertToAllowedSepaCharacters(edtxtRemitteeName.text.toString()), edtxtRemitteeIban.text.toString().replace(" ", ""), edtxtRemitteeBic.text.toString().replace(" ", ""), amount, - edtxtUsage.text.toString(), + inputValidator.convertToAllowedSepaCharacters(edtxtUsage.text.toString()), chkbxInstantPayment.isChecked ) diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt index 3b4fc027..9027c546 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/util/InputValidator.kt @@ -78,7 +78,11 @@ open class InputValidator { } 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) }