RedisGraph / RedisGraph

A graph database as a Redis module
https://redis.io/docs/stack/graph/
Other
2k stars 229 forks source link

Escaping ` in symbolic name does not work (node label, relationship type, property key, variable, parameter) #1187

Open kdojeteri opened 4 years ago

kdojeteri commented 4 years ago

I was trying to figure out a universal way to safely pass arbitrary node labels to a query. I read this bit in OpenCypher's antlr4 grammar, which lead me to think I could just use backticks:

/**
 * Any character except "`", enclosed within `backticks`. Backticks are escaped with double backticks.
 */
EscapedSymbolicName
                   :  ( '`' ( EscapedSymbolicName_0 )* '`' )+ ;

Unfortunately, the backticks are escaped with double backticks bit doesn't work in redis-graph. This query creates a node with the label Foobar`123, but redis-graph throws an error:

>> GRAPH.QUERY portal-graph "MERGE (:`Foobar``123`)"
(error) errMsg: Invalid input '`': expected a label, '{', a parameter or ')' line: 1, column: 17, offset: 16 errCtx: MERGE (:`Foobar``123`) errCtxOffset: 16
DvirDukhan commented 4 years ago

@kdojeteri This is our libcypher-parser error of invalid query. I tried your query also in Neo4J and it didn't work. image There is a note that a backtick should be escaped with double backticks but I couldn't get this variant to work either in neo4j or RedisGraph can you specify a working query that fails on RedisGraph?

kdojeteri commented 4 years ago

I hate to do a "works on my machine", but here's a video as proof that the original query works: https://ctrlv.tv/6VDS

Neo4j Browser version: 4.0.10

Neo4j Server version: 3.5.19 (community)

DvirDukhan commented 4 years ago

@kdojeteri It is confirmed to work on neo4j 3.5.19 but not working on the latest version. I will query with neo4j for this regression. If this feature is still valid I'll contact Chris Leishman, who maintains the libcypher-parser and open an issue/PR.