Allow tg:// links in text url entities

This commit is contained in:
Ilya Laktyushin 2019-09-20 23:50:21 +03:00
parent e26eedc664
commit 4408dc8f5a
2 changed files with 9 additions and 7 deletions

View File

@ -406,7 +406,7 @@ func chatTextLinkEditController(sharedContext: SharedAccountContext, account: Ac
return
}
let updatedLink = explicitUrl(contentNode.link)
if !updatedLink.isEmpty && isValidUrl(updatedLink) {
if !updatedLink.isEmpty && isValidUrl(updatedLink, validSchemes: ["http": true, "https": true, "tg": false, "ton": false]) {
dismissImpl?(true)
apply(updatedLink)
} else {

View File

@ -34,12 +34,14 @@ public extension CharacterSet {
}()
}
public func isValidUrl(_ url: String) -> Bool {
if let escapedUrl = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: escapedUrl), ["http", "https"].contains(url.scheme), let host = url.host, host.contains(".") && url.user == nil {
let components = host.components(separatedBy: ".")
let domain = (components.first ?? "")
if domain.isEmpty {
return false
public func isValidUrl(_ url: String, validSchemes: [String: Bool] = ["http": true, "https": true]) -> Bool {
if let escapedUrl = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), let url = URL(string: escapedUrl), let scheme = url.scheme, let requiresTopLevelDomain = validSchemes[scheme], let host = url.host, (!requiresTopLevelDomain || host.contains(".")) && url.user == nil {
if requiresTopLevelDomain {
let components = host.components(separatedBy: ".")
let domain = (components.first ?? "")
if domain.isEmpty {
return false
}
}
return true
} else {