Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Limit donation amount input to 9 characters (#13872) #13877

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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