Skip to content

Commit 788ed25

Browse files
ioanatflowcryptIoan Moldovan
andauthored
fix: formatting issue in reply message with attachment (#2673)
Co-authored-by: Ioan Moldovan <mobilestar108@outlook.com>
1 parent 204da99 commit 788ed25

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

FlowCrypt/Controllers/Threads/ThreadDetailsViewController+TableView.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,12 @@ extension ThreadDetailsViewController: ASTableDelegate, ASTableDataSource {
7878
guard row > 1 + securityWarningBlockCount else {
7979
if processedMessage.text.isHTMLString {
8080
return ThreadDetailWebNode(
81-
input: .init(message: processedMessage.text, quote: processedMessage.quote, index: messageIndex)
81+
input: .init(
82+
message: processedMessage.text,
83+
quote: processedMessage.quote,
84+
index: messageIndex,
85+
isEncrypted: processedMessage.type == .encrypted
86+
)
8287
)
8388
}
8489
return MessageTextSubjectNode(

FlowCryptCommon/Extensions/StringExtensions.swift

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,35 @@ public extension String {
9393
return "tag.fill"
9494
}
9595
}
96-
96+
97+
/// A regex that finds an opening HTML tag and captures its name.
98+
private static let htmlTagRegex: NSRegularExpression? = {
99+
try? NSRegularExpression(
100+
pattern: "<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>",
101+
options: .caseInsensitive
102+
)
103+
}()
104+
105+
/// Returns `true` if this string contains at least one full HTML element
106+
/// (an opening `<tag…>` **and** a matching `</tag>`).
107+
/// Email‑style `<…@…>` or other angle‑bracketed text won’t count.
97108
var isHTMLString: Bool {
98-
do {
99-
let regex = try NSRegularExpression(pattern: "<[a-z][\\s\\S]*>", options: .caseInsensitive)
100-
let range = NSRange(startIndex..., in: self)
101-
return regex.firstMatch(in: self, options: [], range: range) != nil
102-
} catch {
103-
return false
104-
}
109+
guard
110+
let regex = Self.htmlTagRegex,
111+
let match = regex.firstMatch(
112+
in: self,
113+
options: [],
114+
range: NSRange(startIndex..<endIndex, in: self)
115+
),
116+
match.numberOfRanges > 1,
117+
let nameRange = Range(match.range(at: 1), in: self)
118+
else {
119+
return false
120+
}
121+
122+
// Extract the tag name and look for its closing tag
123+
let tagName = String(self[nameRange])
124+
return range(of: "</\(tagName)>", options: .caseInsensitive) != nil
105125
}
106126

107127
func removingHtmlTags() -> String {

FlowCryptUI/Cell Nodes/ThreadDetailWebNode.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ public final class ThreadDetailWebNode: CellNode {
1313
let message: String?
1414
let quote: String?
1515
let index: Int
16+
let isEncrypted: Bool
1617

17-
public init(message: String?, quote: String?, index: Int) {
18+
public init(message: String?, quote: String?, index: Int, isEncrypted: Bool) {
1819
self.message = message
1920
self.quote = quote
2021
self.index = index
22+
self.isEncrypted = isEncrypted
2123
}
2224
}
2325

@@ -50,7 +52,7 @@ public final class ThreadDetailWebNode: CellNode {
5052
self.input = input
5153

5254
super.init()
53-
addLeftBorder(width: .threadLeftBorderWidth, color: .plainTextBorder)
55+
addLeftBorder(width: .threadLeftBorderWidth, color: input.isEncrypted ? .main : .plainTextBorder)
5456
}
5557

5658
private func getFormattedHtml(html: String?) -> String {

0 commit comments

Comments
 (0)