mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-22 00:11:00 +00:00
Escape characters when editing close #811
This commit is contained in:
parent
1b47419458
commit
c4b9e74bcd
3 changed files with 24 additions and 23 deletions
|
@ -59,25 +59,3 @@ extension NotificationService {
|
|||
return info
|
||||
}
|
||||
}
|
||||
|
||||
extension String {
|
||||
func escape() -> String {
|
||||
return replacingOccurrences(of: "&", with: "&")
|
||||
.replacingOccurrences(of: "<", with: "<")
|
||||
.replacingOccurrences(of: ">", with: ">")
|
||||
.replacingOccurrences(of: """, with: "\"")
|
||||
.replacingOccurrences(of: "'", with: "'")
|
||||
.replacingOccurrences(of: "'", 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
|
||||
}
|
||||
}
|
||||
|
|
23
Packages/Network/Sources/Network/String.swift
Normal file
23
Packages/Network/Sources/Network/String.swift
Normal file
|
@ -0,0 +1,23 @@
|
|||
import Foundation
|
||||
|
||||
extension String {
|
||||
public func escape() -> String {
|
||||
return replacingOccurrences(of: "&", with: "&")
|
||||
.replacingOccurrences(of: "<", with: "<")
|
||||
.replacingOccurrences(of: ">", with: ">")
|
||||
.replacingOccurrences(of: """, with: "\"")
|
||||
.replacingOccurrences(of: "'", with: "'")
|
||||
.replacingOccurrences(of: "'", 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
|
||||
}
|
||||
}
|
|
@ -256,7 +256,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
|
|||
self.visibility = visibility
|
||||
selectedRange = .init(location: statusText.string.utf16.count, length: 0)
|
||||
case let .edit(status):
|
||||
var rawText = status.content.asRawText
|
||||
var rawText = status.content.asRawText.escape()
|
||||
for mention in status.mentions {
|
||||
rawText = rawText.replacingOccurrences(of: "@\(mention.username)", with: "@\(mention.acct)")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue