mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
added tests
improvement improved improvement fixed
This commit is contained in:
@@ -118,3 +118,22 @@ extension String {
|
||||
return UTType(filenameExtension: fileExtension) != nil ? fileExtension : "bin"
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
/// To be used if the string is actually a URL
|
||||
var asSanitizedLink: String {
|
||||
var link = self
|
||||
if !link.contains("://") {
|
||||
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
|
||||
while !link.isEmpty,
|
||||
link.rangeOfCharacter(from: .punctuationCharacters, options: .backwards)?.upperBound == link.endIndex {
|
||||
link = String(link.dropLast())
|
||||
}
|
||||
|
||||
return link
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user