Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Graph doesn't allow single quote to be escaped when creating a vertex/edge #188

Open
tperry opened this issue Oct 30, 2018 · 2 comments

Comments

@tperry
Copy link

tperry commented Oct 30, 2018

Here's an example of the problem we've encountered when trying to create a vertex that has a string attribute whose value contains a single quote.

    RedisGraphAPI api = new RedisGraphAPI("videoDB");
    api.query( "CREATE (:person{name:'roi\'s', age:32})" );

Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: Syntax error at offset 28 near 's'
at redis.clients.jedis.Protocol.processError(Protocol.java:131)
at redis.clients.jedis.Protocol.process(Protocol.java:165)
at redis.clients.jedis.Protocol.read(Protocol.java:219)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:309)
at redis.clients.jedis.Connection.getRawObjectMultiBulkReply(Connection.java:276)
at redis.clients.jedis.Connection.getObjectMultiBulkReply(Connection.java:280)
at com.redislabs.redisgraph.RedisGraphAPI.query(RedisGraphAPI.java:58)
at com.oncam.saas.redisgraph.OrientDbImport.main(OrientDbImport.java:239)
Oct 30, 2018 7:30:26 AM com.orientechnologies.common.log.OLogManager log
INFO: Orient Engine is shutting down...

We also occasionally get a syntax error when trying to create a vertex that contains a String property. I believe the error is caused by the occurrence of a special character in the value of a String property. It would be nice if the list of special characters that need to be escaped was documented and also if the syntax error provided more information about the specific cause of the error.

Thomas Perry
Oncam

@tperry tperry changed the title erty Redis Graph doesn't allow single quote to be escaped when creating a vertex/edge Oct 30, 2018
@swilly22
Copy link
Collaborator

Hi @tperry, most defiantly, we'll be adding escape character right after we publish our GA mid November, also we should better handle errors from our different clients, in the meanwhile whenever you encounter such an error which isn't verbose enough I'll suggest issuing the faulting query directly to redis using redis-cli to get better error reporting.

@K-Jo
Copy link
Collaborator

K-Jo commented Mar 12, 2019

The issue here is a combination of the lexer inside RedisGraph and the way the client/redis-cli escapes strings. Lets' consider following examples:

redis:6379> set foo "b\"a'r"
OK
redis:6379> get foo
"b\"a'r"
redis:6379> set foo 'b\'a"r'
OK
redis:6379> get foo
"b'a\"r"
redis:6379>

as we can see, both the values will be converted into double quoted strings. This can also be observed by execution the https://redis.io/commands/monitor command that shows which command the server actually received

1552313854.883530 [0 172.17.0.3:59574] "set" "foo" "b\"a'r"
1552313868.409694 [0 172.17.0.3:59574] "get" "foo"
1552313880.315356 [0 172.17.0.3:59574] "set" "foo" "b'a\"r"
1552313891.599945 [0 172.17.0.3:59574] "get" "foo"

Transforming this into cypher statements we get the following output

redis:6379> graph.query g "create ({name:'roi\'s'})"
(error) Syntax error at offset 21 near 's'
redis:6379> graph.query g "create ({name:\"roi's\"})"
1) (empty list or set)
2) 1) "Nodes created: 1"
   2) "Properties set: 1"
   3) "Query internal execution time: 0.301400 milliseconds"
redis:6379> graph.query g "create ({name:'roi\"s'})"
1) (empty list or set)
2) 1) "Nodes created: 1"
   2) "Properties set: 1"
   3) "Query internal execution time: 0.296800 milliseconds"
redis:6379> graph.query g "create ({name:'r\"oi\\'s'})"
1) (empty list or set)
2) 1) "Nodes created: 1"
  2) "Properties set: 1"
  3) "Query internal execution time: 0.502100 milliseconds"

and this is what Redis received (via monitor command)

1552314569.830566 [0 172.17.0.3:59574] "graph.query" "g" "create ({name:'roi's'})"
1552315222.436296 [0 172.17.0.3:59574] "graph.query" "g" "create ({name:\"roi's\"})"
1552315903.156545 [0 172.17.0.3:59574] "graph.query" "g" "create ({name:'roi\"s'})"
1552346432.867078 [0 172.17.0.1:58942] "graph.query" "g" "create ({name:'r\"oi\\'s'})"

The first query can't be interpreted by the current lexer of redisgraph since it can't understand where the value of name starts and ends.
The second and the third query are the correct examples where you need to escape either a single or a double quote. However, they can't combine both single and double qoutes within the same property
The last example allows you to combine single and double escaped characters, however, you would have to parse the result after it was returned by the database to remove the unintended symbols.

127.0.0.1:6379> graph.query g "match (n) return n"
n.name
r"oi\'s

In case of the java client more specifically, we currently recommend option 2 until we have finalised our effort to support the new cypher parser #369

We are still actively investigating a potential enhancement to this issue meanwhile (before we have the full parser support) and will get back on this issue soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants