escaping special chars

25 views
Skip to first unread message

Byron Appelt

unread,
Nov 17, 2014, 12:07:19 PM11/17/14
to neo...@googlegroups.com
I am working on a site, http://gempact.com, 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

unread,
Nov 17, 2014, 12:18:48 PM11/17/14
to neo...@googlegroups.com
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

unread,
Dec 5, 2014, 5:55:46 PM12/5/14
to neo...@googlegroups.com
Chris, 

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
  include
Neo4j::ActiveNode
  property
:name
end

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

unread,
Dec 5, 2014, 6:03:39 PM12/5/14
to neo...@googlegroups.com
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 https://github.com/neo4jrb/neo4j/wiki/Neo4j.rb-v4-Introduction for more info.

Chris
--
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 neo4jrb+u...@googlegroups.com.
To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb.
For more options, visit https://groups.google.com/d/optout.

Byron Appelt

unread,
Dec 8, 2014, 2:09:44 PM12/8/14
to neo...@googlegroups.com
Thanks Chris, Definitely works better, but I think there is still a problem when updating properties. I submitted an issue: https://github.com/neo4jrb/neo4j/issues/633

Chris Grigg

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