Skip to content

Commit

Permalink
Merge branch 'master' into candidate
Browse files Browse the repository at this point in the history
Merge master into candidate
  • Loading branch information
munir-rakuten committed Oct 18, 2023
2 parents 239b2f6 + 466c955 commit 5a4b904
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 29 deletions.
2 changes: 1 addition & 1 deletion miniapp/src/main/assets/js-miniapp
Submodule js-miniapp updated 1 files
+11 −5 bridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import com.rakuten.tech.mobile.miniapp.permission.CustomPermissionBridgeDispatch
import com.rakuten.tech.mobile.miniapp.permission.MiniAppCustomPermissionResult
import com.rakuten.tech.mobile.miniapp.permission.ui.MiniAppCustomPermissionWindow
import com.rakuten.tech.mobile.miniapp.storage.DownloadedManifestCache
import java.nio.charset.Charset

@Suppress(
"TooGenericExceptionCaught",
Expand Down Expand Up @@ -711,35 +710,9 @@ internal object ErrorBridgeMessage {
@Suppress("ExpressionBodySyntax", "SwallowedException", "TooGenericExceptionCaught")
fun String.base64Encoded(): String = try {
Base64.encodeToString(
encodeToNonLossyAscii(this).toByteArray(charset("UTF-8")),
this.toByteArray(charset("UTF-8")),
Base64.DEFAULT
)
} catch (e: Exception) {
""
}

/**
* convert the unicode/octal characters.
*/
@Suppress("MagicNumber")
private fun encodeToNonLossyAscii(original: String): String {
val asciiCharset = Charset.forName("US-ASCII")
if (asciiCharset.newEncoder().canEncode(original)) {
return original
}
val stringBuffer = StringBuffer()
for (element in original) {
if (element.code < 128) {
stringBuffer.append(element)
} else if (element.code < 256) {
val octal = Integer.toOctalString(element.code)
stringBuffer.append("\\")
stringBuffer.append(octal)
} else {
val hex = Integer.toHexString(element.code)
stringBuffer.append("\\u")
stringBuffer.append(hex)
}
}
return stringBuffer.toString()
}

0 comments on commit 5a4b904

Please sign in to comment.