Refactor base64 decode function to simplify handling (#3411)

Refactored the decode function to simplify base64 decoding and improve handling of various base64 formats. Removed redundant code and improved clarity.
This commit is contained in:
Tamim Hossain
2024-08-03 08:35:15 +06:00
committed by GitHub
parent 52699967cd
commit 6e6ca209df

View File

@@ -97,14 +97,10 @@ object Utils {
* base64 decode
*/
fun decode(text: String?): String {
tryDecodeBase64(text)?.let { return it }
if (text?.endsWith('=')==true) {
// try again for some loosely formatted base64
tryDecodeBase64(text.trimEnd('='))?.let { return it }
}
return ""
return tryDecodeBase64(text) ?: text?.trimEnd('=')?.let { tryDecodeBase64(it) } ?: ""
}
fun tryDecodeBase64(text: String?): String? {
try {
return Base64.decode(text, Base64.NO_WRAP).toString(Charsets.UTF_8)