escaping special chars

Skip to first unread message

Byron Appelt

Nov 17, 2014, 12:07:19 PM11/17/14
I am working on a site,, that stores information on RubyGems and a lot of the gem descriptions, which I am storing as a property, contain special characters that of course need to be escaped in cypher. 

which suggested I use:

gsub( /([\+\-\&\|\!\(\)\{\}\[\]\^\"\~\*\?\:\\])/ , "\\\1" )

Which almost worked, but I had to change "\\\1" to "\\\\\\1" for reasons related to multiple levels of escaping that I don't fully understand. 

I have two questions. First, should I correct the wiki page where I found the regex substitution? I can't find anywhere that page is linked from, so I wasn't sure if it is the current documentation or not.

My next question is whether or not I should really be having to do this? 

It seem to me that working with other libraries like activerecord, if I set a property on a model to a value, the ORM library should do whatever is necessary in the way of escaping, etc. to save that value as given. 

Am I wrong about that? Would a pull request along those lines be accepted?  


Chris Grigg

Nov 17, 2014, 12:18:48 PM11/17/14
Hi Byron! That page is from the legacy documentation. Only docs under the "Neo4jrb v3.0" heading in the right-hand table of contents are current, the gem was completely rewritten for 3.0, so don't worry about this unless you're still using v2.3.

Byron Appelt

Dec 5, 2014, 5:55:46 PM12/5/14

Are you saying that I shouldn't have to do the escaping? That would be my expectation, but I don't think it is working correctly. For example, I have a model RubyGem:

class RubyGem

If I wan't to set the name to \' (that's actually backslash single-quote, not an escape sequence), it seems like I should be able to do it like this:

> RubyGem.create(name: "\\'")
Neo4j::Server::CypherResponse::ResponseError: Invalid input ''': expected whitespace, '.', node labels, '[', "=~", IN, IS, '^', '*', '/', '%', '+', '-', '<', '>', "<=", ">=", '=', "<>", "!=", AND, XOR, OR, ',' or '}' (line 1, column 79)
"CREATE (n:`RubyGem` {uuid : '
670b082e-a15f-41d3-ba2b-dd0fdf569d30',name : '\\'',_classname : 'RubyGem'}) RETURN ID(n)"

but as you can see, that doesn't work. 

Chris Grigg

Dec 5, 2014, 6:03:39 PM12/5/14
We just released 4.0.0.rc.1 and among other things, it corrects a bug dealing with escaping properties during creation. I just tested what you have below and it worked using this release. See for more info.

You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
For more options, visit

Byron Appelt

Dec 8, 2014, 2:09:44 PM12/8/14
Thanks Chris, Definitely works better, but I think there is still a problem when updating properties. I submitted an issue:

Chris Grigg

Jan 6, 2015, 8:31:09 PM1/6/15
Old post but just commenting here for posterity, this was cleared up with patches to neo4j-core.
Reply all
Reply to author
0 new messages