diff --git a/apps/ios/Shared/Views/Chat/ChatItem/CILinkView.swift b/apps/ios/Shared/Views/Chat/ChatItem/CILinkView.swift index 3433115ceb..42259361b7 100644 --- a/apps/ios/Shared/Views/Chat/ChatItem/CILinkView.swift +++ b/apps/ios/Shared/Views/Chat/ChatItem/CILinkView.swift @@ -106,13 +106,12 @@ func unicodeMarker(_ s: Unicode.Scalar) -> String { } func displayedUri(_ uri: String) -> String { - let authority = uri.range(of: "://").map { scheme in - scheme.upperBound ..< (uri[scheme.upperBound...].firstIndex(where: { "/?#".contains($0) }) ?? uri.endIndex) - } + let authorityStart = uri.range(of: "://")?.upperBound ?? uri.startIndex + let authority = authorityStart ..< (uri[authorityStart...].firstIndex(where: { "/?#".contains($0) }) ?? uri.endIndex) var shown = "" for i in uri.unicodeScalars.indices { let s = uri.unicodeScalars[i] - if s.properties.generalCategory == .format || (!s.isASCII && authority?.contains(i) == true) { + if s.properties.generalCategory == .format || (!s.isASCII && authority.contains(i)) { shown += unicodeMarker(s) } else { shown.unicodeScalars.append(s) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Utils.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Utils.kt index 6b69a3820f..81a64cb527 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Utils.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/Utils.kt @@ -632,7 +632,7 @@ private val nonAsciiChar = Regex("[^\\x00-\\x7F]") fun unicodeMarker(c: String): String = "[U+" + Integer.toHexString(c.codePointAt(0)).uppercase().padStart(4, '0') + "]" fun displayedUri(uri: String): String { - val authorityStart = uri.indexOf("://").takeIf { it >= 0 }?.plus(3) ?: uri.length + val authorityStart = uri.indexOf("://").takeIf { it >= 0 }?.plus(3) ?: 0 val authorityEnd = uri.indexOfAny(charArrayOf('/', '?', '#'), authorityStart).takeIf { it >= 0 } ?: uri.length val authority = uri.substring(authorityStart, authorityEnd).replace(nonAsciiChar) { unicodeMarker(it.value) } return uri.replaceRange(authorityStart, authorityEnd, authority).replace(invisibleChar) { unicodeMarker(it.value) }