Skip to content

Commit

Permalink
Refactor base64 decode function to simplify handling (#3411)
Browse files Browse the repository at this point in the history
Refactored the decode function to simplify base64 decoding and improve handling of various base64 formats. Removed redundant code and improved clarity.
  • Loading branch information
CodeWithTamim authored Aug 3, 2024
1 parent 5269996 commit 6e6ca20
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6e6ca20

Please sign in to comment.