Skip to content

Commit

Permalink
Fix: Limit donation amount input to 9 characters (#13872)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
shahrukhahmed94 committed Jan 4, 2025
1 parent ba79a3e commit c08af2e
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c08af2e

Please sign in to comment.