From c08af2e1bd85fc6a87fe44ad3d37801c6441373a Mon Sep 17 00:00:00 2001 From: devavanza Date: Sun, 5 Jan 2025 02:35:43 +0500 Subject: [PATCH] Fix: Limit donation amount input to 9 characters (#13872) - Added validation in MoneyFilter to restrict input to 9 characters. - Updated both filter and afterTextChanged methods to enforce this limit. - Ensured edge cases and formatting remain functional. - Resolves #13872. --- .../settings/app/subscription/boost/Boost.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/boost/Boost.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/boost/Boost.kt index 2a4a31bad32..7e9acfcafd3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/boost/Boost.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/subscription/boost/Boost.kt @@ -257,6 +257,11 @@ data class Boost( val result = dest.subSequence(0, dstart).toString() + source.toString() + dest.subSequence(dend, dest.length) val resultWithoutCurrencyPrefix = StringUtil.stripBidiIndicator(result.removePrefix(symbol).removeSuffix(symbol).trim()) + // Enforce maximum length of 9 characters + if (resultWithoutCurrencyPrefix.length > 9) { + return "" // Reject the new input + } + if (resultWithoutCurrencyPrefix.length == 1 && !resultWithoutCurrencyPrefix.isDigitsOnly() && resultWithoutCurrencyPrefix != separator.toString()) { return dest.subSequence(dstart, dend) } @@ -278,6 +283,7 @@ data class Boost( if (s.isNullOrEmpty()) return val hasSymbol = s.startsWith(symbol) || s.endsWith(symbol) + if (hasSymbol && symbolPattern.matchEntire(s.toString()) != null) { s.clear() } else if (!hasSymbol) { @@ -312,6 +318,13 @@ data class Boost( } val withoutSymbol = s.removePrefix(symbol).removeSuffix(symbol).trim().toString() + + // Check if the value exceeds 9 characters + if (withoutSymbol.length > 9) { + s.delete(9, s.length) // Trim to the first 9 characters + return + } + val withoutLeadingZeroes: String = try { NumberFormat.getInstance().apply { isGroupingUsed = false