mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 08:12:40 +00:00
Merge pull request #6759 from vector-im/aringenbach/6748_fix_percent_encoding_and_markdown
Fix render of links with both characters requiring percent encoding and markdown-like syntax
This commit is contained in:
commit
b5184faa4a
3 changed files with 18 additions and 2 deletions
|
@ -166,10 +166,11 @@ private extension CMarkNode {
|
|||
private extension String {
|
||||
/// Returns array of URLs detected inside the String.
|
||||
var containedUrls: [NSTextCheckingResult] {
|
||||
guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) else {
|
||||
guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue),
|
||||
let percentEncoded = self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else {
|
||||
return []
|
||||
}
|
||||
|
||||
return detector.matches(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count))
|
||||
return detector.matches(in: percentEncoded, options: [], range: NSRange(location: 0, length: percentEncoded.utf16.count))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,6 +112,20 @@ final class MarkdownToHTMLRendererTests: XCTestCase {
|
|||
testRenderHTML(input: input, expectedOutput: expectedOutput)
|
||||
}
|
||||
|
||||
func testRenderRepairedLinksWithCharactersRequiringPercentEncoding() {
|
||||
let input = "Some link with special characters: "
|
||||
+ "https://matrix.to/#/#_oftc_#matrix-dev:matrix.org"
|
||||
+ " "
|
||||
+ "https://matrix.to/#/#?=+-_#_"
|
||||
+ "\n"
|
||||
let expectedOutput = "<p>Some link with special characters: "
|
||||
+ "https://matrix.to/#/#_oftc_#matrix-dev:matrix.org"
|
||||
+ " "
|
||||
+ "https://matrix.to/#/#?=+-_#_</p>"
|
||||
+ "\n"
|
||||
testRenderHTML(input: input, expectedOutput: expectedOutput)
|
||||
}
|
||||
|
||||
/// Test links inside codeblocks.
|
||||
func testRenderLinksInCodeblock() {
|
||||
let input = "```"
|
||||
|
|
1
changelog.d/6748.bugfix
Normal file
1
changelog.d/6748.bugfix
Normal file
|
@ -0,0 +1 @@
|
|||
Fix render of links with both characters requiring percent encoding and markdown-like syntax
|
Loading…
Reference in a new issue