unify http(s) protocoll prefix check on urls

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2022-03-11 14:30:44 +01:00
parent 9223727e00
commit 454dbc5db2
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
7 changed files with 18 additions and 13 deletions

View file

@ -53,6 +53,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.stfalcon.chatkit.messages.MessageHolders
import java.net.URLEncoder
@ -218,7 +219,7 @@ class IncomingLocationMessageViewHolder(incomingView: View, payload: Any) : Mess
binding.webview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
return if (url != null && (url.startsWith("http://") || url.startsWith("https://"))
return if (url != null && UriUtils.hasHttpProtocollPrefixed(url)
) {
view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
true

View file

@ -47,6 +47,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.chat.ReadStatus
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.UriUtils
import com.stfalcon.chatkit.messages.MessageHolders
import java.net.URLEncoder
import javax.inject.Inject
@ -131,7 +132,7 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
binding.webview.webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
return if (url != null && (url.startsWith("http://") || url.startsWith("https://"))
return if (url != null && UriUtils.hasHttpProtocollPrefixed(url)
) {
view?.context?.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
true

View file

@ -48,6 +48,7 @@ import com.nextcloud.talk.models.json.generic.Status
import com.nextcloud.talk.models.json.userprofile.UserProfileOverall
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.ClosedInterfaceImpl
import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_BASE_URL
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_INTERNAL_USER_ID
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT
@ -113,8 +114,7 @@ class AccountVerificationController(args: Bundle? = null) :
actionBar?.hide()
if (isAccountImport &&
!baseUrl!!.startsWith("http://") &&
!baseUrl!!.startsWith("https://") ||
!UriUtils.hasHttpProtocollPrefixed(baseUrl!!) ||
!TextUtils.isEmpty(originalProtocol!!) &&
!baseUrl!!.startsWith(originalProtocol!!)
) {

View file

@ -48,6 +48,7 @@ import com.nextcloud.talk.utils.AccountUtils.findAccounts
import com.nextcloud.talk.utils.AccountUtils.getAppNameBasedOnPackage
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_IS_ACCOUNT_IMPORT
import com.nextcloud.talk.utils.database.user.UserUtils
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder
@ -197,7 +198,7 @@ class ServerSelectionController : NewBaseController(R.layout.controller_server_s
url = url.substring(0, url.length - 1)
}
val queryUrl = url + ApiUtils.getUrlPostfixForStatus()
if (url.startsWith("http://") || url.startsWith("https://")) {
if (UriUtils.hasHttpProtocollPrefixed(url)) {
checkServer(queryUrl, false)
} else {
checkServer("https://$queryUrl", true)

View file

@ -46,6 +46,7 @@ import com.nextcloud.talk.controllers.util.viewBinding
import com.nextcloud.talk.databinding.ControllerEntryMenuBinding
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.utils.ShareUtils
import com.nextcloud.talk.utils.UriUtils
import com.nextcloud.talk.utils.bundle.BundleKeys
import com.nextcloud.talk.utils.database.user.UserUtils
import com.nextcloud.talk.utils.singletons.ApplicationWideMessageHolder
@ -117,9 +118,11 @@ class EntryMenuController(args: Bundle) :
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
// unused atm
}
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
// unused atm
}
override fun afterTextChanged(s: Editable) {
if (!TextUtils.isEmpty(s)) {
if (operation === ConversationOperationEnum.OPS_CODE_RENAME_ROOM) {
@ -143,10 +146,7 @@ class EntryMenuController(args: Bundle) :
}
binding.textInputLayout.isErrorEnabled = false
} else if (
(
binding.textEdit.text.toString().startsWith("http://") ||
binding.textEdit.text.toString().startsWith("https://")
) &&
UriUtils.hasHttpProtocollPrefixed(binding.textEdit.text.toString()) &&
binding.textEdit.text.toString().contains("/call/")
) {
if (!binding.okButton.isEnabled) {

View file

@ -55,10 +55,7 @@ object AccountUtils {
internalUserEntity = userEntitiesList[i]
importAccount = getInformationFromAccount(account)
if (importAccount.token != null) {
if (
importAccount.baseUrl.startsWith("http://") ||
importAccount.baseUrl.startsWith("https://")
) {
if (UriUtils.hasHttpProtocollPrefixed(importAccount.baseUrl)) {
if (
internalUserEntity.username == importAccount.username &&
internalUserEntity.baseUrl == importAccount.baseUrl

View file

@ -24,6 +24,7 @@ import android.content.Context
import android.database.Cursor
import android.net.Uri
import android.provider.OpenableColumns
import android.text.TextUtils
import android.util.Log
class UriUtils {
@ -50,5 +51,9 @@ class UriUtils {
}
return filename
}
fun hasHttpProtocollPrefixed(uri: String): Boolean {
return uri.startsWith("http://") || uri.startsWith("https://")
}
}
}