mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-19 10:30:46 +00:00
ui: additional check for plain domains (#7699)
Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com>
This commit is contained in:
co-authored by
Evgeny @ SimpleX Chat
parent
d673a6b021
commit
1bd7c95006
@@ -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)
|
||||
|
||||
+1
-1
@@ -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) }
|
||||
|
||||
Reference in New Issue
Block a user