From 02ad847b3cfb21cb9af54903a0d6536f3f13eee1 Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Sun, 8 Sep 2019 18:20:35 +0800 Subject: [PATCH] Fixes #1104. 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. --- ShadowsocksX-NG/LaunchAgentUtils.swift | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ShadowsocksX-NG/LaunchAgentUtils.swift b/ShadowsocksX-NG/LaunchAgentUtils.swift index a606622..3c081af 100644 --- a/ShadowsocksX-NG/LaunchAgentUtils.swift +++ b/ShadowsocksX-NG/LaunchAgentUtils.swift @@ -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)