mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 16:10:20 +00:00
Ignore punctuation characters at the end of detected links
- fixes permalink handling when that's the case - prevents deep linking loops between nightly and the main app
This commit is contained in:
committed by
Stefan Ceriu
parent
f16b9aad0a
commit
bbf5b91675
@@ -110,6 +110,23 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
XCTAssertEqual(link?.host, "www.matrix.org")
|
||||
}
|
||||
|
||||
func testPunctuationAtTheEndOfPlainStringLinks() {
|
||||
let plainString = "This text contains a https://www.matrix.org:;., link."
|
||||
|
||||
guard let attributedString = attributedStringBuilder.fromPlain(plainString) else {
|
||||
XCTFail("Could not build the attributed string")
|
||||
return
|
||||
}
|
||||
|
||||
XCTAssertEqual(String(attributedString.characters), plainString)
|
||||
|
||||
XCTAssertEqual(attributedString.runs.count, 3)
|
||||
|
||||
let link = attributedString.runs.first(where: { $0.link != nil })?.link
|
||||
|
||||
XCTAssertEqual(link?.host, "www.matrix.org")
|
||||
}
|
||||
|
||||
func testLinkDefaultScheme() {
|
||||
let plainString = "This text contains a matrix.org link."
|
||||
|
||||
@@ -177,9 +194,13 @@ class AttributedStringBuilderTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testLinkWithFragment() {
|
||||
let string = "https://example.com/#/"
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expectedLink: string, expectedRuns: 1)
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expectedLink: string, expectedRuns: 1)
|
||||
var string = "https://example.com/#/"
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expectedLink: "https://example.com", expectedRuns: 1)
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expectedLink: "https://example.com", expectedRuns: 1)
|
||||
|
||||
string = "https://example.com/#/some_fragment/"
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromHTML(string), expectedLink: "https://example.com/#/some_fragment", expectedRuns: 1)
|
||||
checkLinkIn(attributedString: attributedStringBuilder.fromPlain(string), expectedLink: "https://example.com/#/some_fragment", expectedRuns: 1)
|
||||
}
|
||||
|
||||
func testPermalink() {
|
||||
|
||||
Reference in New Issue
Block a user