mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Fix #4946 - Linkification strips trailing brackets from URLs
This commit is contained in:
committed by
Stefan Ceriu
parent
4cfedefcca
commit
29dfba140d
@@ -30,4 +30,10 @@ extension CharacterSet {
|
||||
|
||||
static let matrixUserIDAllowedCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyz0123456789._=-/@:")
|
||||
static let roomAliasAllowedCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyz0123456789!$&‘()*+/;=?@[]-._:#")
|
||||
|
||||
static let punctuationWithoutClosingBracketCharacters: CharacterSet = {
|
||||
var baseSet: CharacterSet = .punctuationCharacters
|
||||
baseSet.remove(")")
|
||||
return baseSet
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -125,10 +125,11 @@ extension String {
|
||||
link.insert(contentsOf: "https://", at: link.startIndex)
|
||||
}
|
||||
|
||||
// Don't include punctuation characters at the end of links
|
||||
// e.g `https://element.io/blog:` <- which is a valid link but the wrong place
|
||||
// Don't include punctuation characters at the end of links but keep
|
||||
// closing brackets as per https://github.com/element-hq/element-x-ios/issues/4946
|
||||
// e.g `https://element.io/blog:` which is a valid link but the wrong place
|
||||
while !link.isEmpty,
|
||||
link.rangeOfCharacter(from: .punctuationCharacters, options: .backwards)?.upperBound == link.endIndex {
|
||||
link.rangeOfCharacter(from: .punctuationWithoutClosingBracketCharacters, options: .backwards)?.upperBound == link.endIndex {
|
||||
link = String(link.dropLast())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user