added tests

improvement

improved

improvement

fixed
This commit is contained in:
Mauro Romito
2025-03-13 20:48:24 +01:00
committed by Mauro
parent 516892ed7b
commit aa35bfc245
12 changed files with 504 additions and 104 deletions
@@ -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
}
}