Skip to content

Commit

Permalink
Fix crash trying to decode requests
Browse files Browse the repository at this point in the history
  • Loading branch information
greenart7c3 committed Dec 25, 2024
1 parent c838047 commit 9d68102
Showing 1 changed file with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ object IntentUtils {
return bunkerRequests
}

private fun decodeData(data: String, replace: Boolean = true): String {
if (!replace) return URLDecoder.decode(data.replace("nostrsigner:", ""), "utf-8")
return URLDecoder.decode(data.replace("nostrsigner:", "").replace("+", "%2b"), "utf-8")
}

private fun getIntentDataWithoutExtras(
context: Context,
data: String,
Expand All @@ -120,8 +125,9 @@ object IntentUtils {
} else {
content = ""
}
val localData = content.ifEmpty { URLDecoder.decode(data.replace("nostrsigner:", "").split("?").first().replace("+", "%2b"), "utf-8") }
val parameters = if (content.isEmpty()) data.replace("nostrsigner:", "").split("?").toMutableList() else data.replace(content, "").replace("nostrsigner:", "").split("?").toMutableList()
val decoded = decodeData(data)
val localData = content.ifEmpty { decoded.split("?").first() }
val parameters = if (content.isEmpty()) decoded.split("?").toMutableList() else decodeData(content, false).split("?").toMutableList()
parameters.removeAt(0)
parameters.removeIf { it.isBlank() }

Expand Down Expand Up @@ -618,11 +624,7 @@ object IntentUtils {

val data =
try {
if (packageName == null) {
URLDecoder.decode(intent.data?.toString()?.replace("+", "%2b") ?: "", "utf-8").replace("nostrsigner:", "")
} else {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
}
decodeData(intent.data?.toString() ?: "", packageName == null)
} catch (e: Exception) {
intent.data?.toString()?.replace("nostrsigner:", "") ?: ""
}
Expand Down Expand Up @@ -812,7 +814,7 @@ object IntentUtils {
val relays: MutableList<RelaySetupInfo> = mutableListOf()
var name = ""
val pubKey = split.first()
val parsedData = URLDecoder.decode(split.drop(1).joinToString { it }.replace("+", "%2b"), "utf-8")
val parsedData = decodeData(split.drop(1).joinToString { it })
val splitParsedData = parsedData.split("&")
val permissions = mutableListOf<Permission>()
var nostrConnectSecret = ""
Expand Down

0 comments on commit 9d68102

Please sign in to comment.