【发布时间】:2017-11-12 23:17:31
【问题描述】:
我有这个查询,因为你的名字包含单引号 Anthony O'Neil
:> g.addV('person')
.property('firstName', 'Anthony O'Neil')
.property('lastName', 'Andersen')
.property('age', 44)
任何想法如何逃脱它?
【问题讨论】:
我有这个查询,因为你的名字包含单引号 Anthony O'Neil
:> g.addV('person')
.property('firstName', 'Anthony O'Neil')
.property('lastName', 'Andersen')
.property('age', 44)
任何想法如何逃脱它?
【问题讨论】:
使用 \
转义撇号所以你的 Gremlin 变成了:
:> g.addV('person')
.property('firstName', 'Anthony O\'Neil')
.property('lastName', 'Andersen')
.property('age', 44)
【讨论】:
找到答案
编码使用这个: encodeURIComponent("Anthony O'Neil").replace(/[!'()*]/g, escape) 输出为:Anthony%20O%27Neil
解码使用这个: decodeURIComponent("Anthony%20O%27Neil") 你会找回安东尼奥尼尔
如果您只想转义单引号,请使用以下代码进行编码: "安东尼奥尼尔".replace(/[!'()*]/g, 转义) 输出:安东尼奥%27尼尔
和上面的解码功能相同
【讨论】:
g.AddV('O%27Neil')输入会产生:[ { "id": "80961abe-3fad-4947-95f1-592bafd1e7f9", "label": "O%27Neil", "type": "vertex" } ]g.AddV('O\'Neil')输入会产生:[ { "id": "68c6bb4e-6f2c-4e5e-99c7-5d653d4ebfb1", "label": "O'Neil", "type": "vertex" } ]