From 54789b6adc3a7716c31b3d634b2afe55d95d9724 Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 23 Sep 2022 13:10:03 -0300 Subject: [wallet] Support uppercase URIs --- .../src/main/java/net/taler/common/TalerUri.kt | 2 +- wallet/src/main/AndroidManifest.xml | 3 +++ .../src/main/java/net/taler/wallet/MainActivity.kt | 20 +++++++++++--------- .../main/java/net/taler/wallet/UriInputFragment.kt | 2 +- wallet/src/main/java/net/taler/wallet/Utils.kt | 2 +- .../wallet/transactions/TransactionDetailFragment.kt | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/taler-kotlin-android/src/main/java/net/taler/common/TalerUri.kt b/taler-kotlin-android/src/main/java/net/taler/common/TalerUri.kt index a1b7225..999408c 100644 --- a/taler-kotlin-android/src/main/java/net/taler/common/TalerUri.kt +++ b/taler-kotlin-android/src/main/java/net/taler/common/TalerUri.kt @@ -45,7 +45,7 @@ public object TalerUri { } else -> return null } - if (!uri.startsWith(prefix)) return null + if (!uri.startsWith(prefix, ignoreCase = true)) return null val parts = uri.let { (if (it.endsWith("/")) it.dropLast(1) else it).substring(prefix.length).split('/') } diff --git a/wallet/src/main/AndroidManifest.xml b/wallet/src/main/AndroidManifest.xml index 7a924be..69670c3 100644 --- a/wallet/src/main/AndroidManifest.xml +++ b/wallet/src/main/AndroidManifest.xml @@ -60,6 +60,9 @@ + diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt index df974ff..5597564 100644 --- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt +++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt @@ -203,7 +203,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener, } } } else { - if (!scheme.startsWith("taler")) { + if (!scheme.startsWith("taler", ignoreCase = true)) { return actionFound } actionFound.postValue(uri.toString()) @@ -223,9 +223,11 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener, val normalizedURL = u.lowercase(ROOT) val action = normalizedURL.substring( - if (normalizedURL.startsWith("taler://")) { + if (normalizedURL.startsWith("taler://", ignoreCase = true)) { "taler://".length - } else if (normalizedURL.startsWith("taler+http://") && model.devMode.value == true) { + } else if (normalizedURL.startsWith("taler+http://", + ignoreCase = true) && model.devMode.value == true + ) { "taler+http://".length } else { normalizedURL.length @@ -233,31 +235,31 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener, ) when { - action.startsWith("pay/") -> { + action.startsWith("pay/", ignoreCase = true) -> { Log.v(TAG, "navigating!") nav.navigate(R.id.action_global_promptPayment) model.paymentManager.preparePay(u) } - action.startsWith("tip/") -> { + action.startsWith("tip/", ignoreCase = true) -> { Log.v(TAG, "navigating!") nav.navigate(R.id.action_global_promptTip) model.tipManager.prepareTip(u) } - action.startsWith("withdraw/") -> { + action.startsWith("withdraw/", ignoreCase = true) -> { Log.v(TAG, "navigating!") // there's more than one entry point, so use global action nav.navigate(R.id.action_global_promptWithdraw) model.withdrawManager.getWithdrawalDetails(u) } - action.startsWith("refund/") -> { + action.startsWith("refund/", ignoreCase = true) -> { model.showProgressBar.value = true model.refundManager.refund(u).observe(this, Observer(::onRefundResponse)) } - action.startsWith("pay-pull/") -> { + action.startsWith("pay-pull/", ignoreCase = true) -> { nav.navigate(R.id.action_global_prompt_pull_payment) model.peerManager.checkPeerPullPayment(u) } - action.startsWith("pay-push/") -> { + action.startsWith("pay-push/", ignoreCase = true) -> { nav.navigate(R.id.action_global_prompt_push_payment) model.peerManager.checkPeerPushPayment(u) } diff --git a/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt index b42e7d1..8ad1fb7 100644 --- a/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/UriInputFragment.kt @@ -59,7 +59,7 @@ class UriInputFragment : Fragment() { } } ui.okButton.setOnClickListener { - if (ui.uriView.text?.startsWith("taler://") == true) { + if (ui.uriView.text?.startsWith("taler://", ignoreCase = true) == true) { ui.uriLayout.error = null val i = Intent(ACTION_VIEW, Uri.parse(ui.uriView.text.toString())) startActivity(i) diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt index 67bc72a..c0ccbed 100644 --- a/wallet/src/main/java/net/taler/wallet/Utils.kt +++ b/wallet/src/main/java/net/taler/wallet/Utils.kt @@ -84,7 +84,7 @@ private fun connectToWifiDeprecated(context: Context, ssid: String) { } fun cleanExchange(exchange: String) = exchange.let { - if (it.startsWith("https://")) it.substring(8) else it + if (it.startsWith("https://", ignoreCase = true)) it.substring(8) else it }.trimEnd('/') fun getAmount(currency: String, text: String): Amount? { diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt index 07b95af..eef2fd3 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt @@ -82,7 +82,7 @@ abstract class TransactionDetailFragment : Fragment() { } else { "${info.summary}\n\n${info.fulfillmentMessage}" } - if (info.fulfillmentUrl?.startsWith("http") == true) { + if (info.fulfillmentUrl?.startsWith("http", ignoreCase = true) == true) { val i = Intent().apply { data = Uri.parse(info.fulfillmentUrl) } -- cgit v1.2.3