Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions redisgraph/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def quote_string(v):
if len(v) == 0:
return '""'

v = v.replace('\\', '\\\\')
v = v.replace('"', '\\"')

return '"{}"'.format(v)
Expand Down
23 changes: 23 additions & 0 deletions tests/functional/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ def test_path(self):
# All done, remove graph.
redis_graph.delete()

def test_properties_with_escapes(self):
redis_graph = Graph('props', self.r)

message = r'This raw string has \ a backslash character in it.'
params = {'message': message}
query = """CREATE (:Foo {message: $message})"""
redis_graph.query(query, params)

query = """MATCH (u:Foo) RETURN u.message"""
result = redis_graph.query(query)
self.assertEqual(result.result_set[0][0], message)

message = r'This raw string has \" a quote preceded by backslash.'
params = {'message': message}
query = """CREATE (:Bar {message: $message})"""
redis_graph.query(query, params)

query = """MATCH (u:Bar) RETURN u.message"""
result = redis_graph.query(query)
self.assertEqual(result.result_set[0][0], message)

redis_graph.delete()

def test_param(self):
redis_graph = Graph('params', self.r)

Expand Down
11 changes: 6 additions & 5 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ def test_random_string(self):

def test_quote_string(self):
self.assertEqual(util.quote_string(10), 10)
self.assertEqual(util.quote_string("abc"), '"abc"')
self.assertEqual(util.quote_string(""), '""')
self.assertEqual(util.quote_string('\"'), '"\\\""')
self.assertEqual(util.quote_string('"'), '"\\""')
self.assertEqual(util.quote_string('a"a'), '"a\\"a"')
self.assertEqual(util.quote_string('abc'), '"abc"')
self.assertEqual(util.quote_string(''), '""')
self.assertEqual(util.quote_string('"'), r'"\""')
self.assertEqual(util.quote_string(r'foo \ bar'), r'"foo \\ bar"')
self.assertEqual(util.quote_string(r'foo \" bar'), r'"foo \\\" bar"')
self.assertEqual(util.quote_string('a"a'), r'"a\"a"')

def test_stringify_param_value(self):
cases = [
Expand Down