This is NSJSONSerialization.dataWithJSONObject that likes to insert additional backslashes.
Escaped forward slashes is also valid json. May be ss-local hasn't handle it correctly.
This commit is contained in:
Qiu Yuzhou
2019-09-08 18:20:35 +08:00
parent fcc362e790
commit 02ad847b3c

View File

@ -129,7 +129,14 @@ func InstallSSLocal() {
func writeSSLocalConfFile(_ conf:[String:AnyObject]) -> Bool {
do {
let filepath = NSHomeDirectory() + APP_SUPPORT_DIR + "ss-local-config.json"
let data: Data = try JSONSerialization.data(withJSONObject: conf, options: .prettyPrinted)
var data: Data = try JSONSerialization.data(withJSONObject: conf, options: .prettyPrinted)
// https://github.com/shadowsocks/ShadowsocksX-NG/issues/1104
// This is NSJSONSerialization.dataWithJSONObject that likes to insert additional backslashes.
// Escaped forward slashes is also valid json.
// Workaround:
let s = String(data:data, encoding: .utf8)!
data = s.replacingOccurrences(of: "\\/", with: "/").data(using: .utf8)!
let oldSum = getFileSHA1Sum(filepath)
try data.write(to: URL(fileURLWithPath: filepath), options: .atomic)