提交 eac49618 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

add escape to json string before send to server

上级 0e20aa4e
......@@ -111,8 +111,21 @@ class Bridge {
* Proxy Call to Wechaty in Bridge
*/
proxyWechaty(wechatyFunc, ...args) {
//const args = Array.prototype.slice.call(arguments, 1)
const argsJson = JSON.stringify(args)
function escape (key, val) {
if (typeof(val)!="string") return val;
return val
.replace(/[\\]/g, '\\\\')
.replace(/[\/]/g, '\\/')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t')
.replace(/[\"]/g, '\\"')
.replace(/\\'/g, "\\'")
} // http://stackoverflow.com/a/14137856/1123955
const argsJson = JSON.stringify(args, escape)
const wechatyScript = `return (Wechaty && Wechaty.${wechatyFunc}.apply(undefined, JSON.parse('${argsJson}')))`
log.silly('Bridge', 'proxyWechaty: ' + wechatyScript)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册