Escape characters when editing close #811

This commit is contained in:
Thomas Ricouard 2023-02-15 06:41:28 +01:00
parent 1b47419458
commit c4b9e74bcd
3 changed files with 24 additions and 23 deletions

View file

@ -59,25 +59,3 @@ extension NotificationService {
return info return info
} }
} }
extension String {
func escape() -> String {
return replacingOccurrences(of: "&", with: "&")
.replacingOccurrences(of: "&lt;", with: "<")
.replacingOccurrences(of: "&gt;", with: ">")
.replacingOccurrences(of: "&quot;", with: "\"")
.replacingOccurrences(of: "&apos;", with: "'")
.replacingOccurrences(of: "&#39;", with: "")
}
func URLSafeBase64ToBase64() -> String {
var base64 = replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
let countMod4 = count % 4
if countMod4 != 0 {
base64.append(String(repeating: "=", count: 4 - countMod4))
}
return base64
}
}

View file

@ -0,0 +1,23 @@
import Foundation
extension String {
public func escape() -> String {
return replacingOccurrences(of: "&amp;", with: "&")
.replacingOccurrences(of: "&lt;", with: "<")
.replacingOccurrences(of: "&gt;", with: ">")
.replacingOccurrences(of: "&quot;", with: "\"")
.replacingOccurrences(of: "&apos;", with: "'")
.replacingOccurrences(of: "&#39;", with: "")
}
public func URLSafeBase64ToBase64() -> String {
var base64 = replacingOccurrences(of: "-", with: "+").replacingOccurrences(of: "_", with: "/")
let countMod4 = count % 4
if countMod4 != 0 {
base64.append(String(repeating: "=", count: 4 - countMod4))
}
return base64
}
}

View file

@ -256,7 +256,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
self.visibility = visibility self.visibility = visibility
selectedRange = .init(location: statusText.string.utf16.count, length: 0) selectedRange = .init(location: statusText.string.utf16.count, length: 0)
case let .edit(status): case let .edit(status):
var rawText = status.content.asRawText var rawText = status.content.asRawText.escape()
for mention in status.mentions { for mention in status.mentions {
rawText = rawText.replacingOccurrences(of: "@\(mention.username)", with: "@\(mention.acct)") rawText = rawText.replacingOccurrences(of: "@\(mention.username)", with: "@\(mention.acct)")
} }