Skip to content

Commit 4a825bc

Browse files
authored
String cleanse (#2548)
* Fixed string escape and added tests * Add Change * Name change
1 parent f46d7f3 commit 4a825bc

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

CHANGES

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Fix string cleanse in Redis Graph
12
* Make PythonParser resumable in case of error (#2510)
23
* Add `timeout=None` in `SentinelConnectionManager.read_response`
34
* Documentation fix: password protected socket connection (#2374)

redis/commands/helpers.py

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def quote_string(v):
115115
if len(v) == 0:
116116
return '""'
117117

118+
v = v.replace("\\", "\\\\")
118119
v = v.replace('"', '\\"')
119120

120121
return f'"{v}"'

tests/test_graph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_path(client):
124124

125125
@pytest.mark.redismod
126126
def test_param(client):
127-
params = [1, 2.3, "str", True, False, None, [0, 1, 2]]
127+
params = [1, 2.3, "str", True, False, None, [0, 1, 2], r"\" RETURN 1337 //"]
128128
query = "RETURN $param"
129129
for param in params:
130130
result = client.graph().query(query, {"param": param})

tests/test_helpers.py

+6
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,9 @@ def test_quote_string():
8080
assert quote_string("hello world!") == '"hello world!"'
8181
assert quote_string("") == '""'
8282
assert quote_string("hello world!") == '"hello world!"'
83+
assert quote_string("abc") == '"abc"'
84+
assert quote_string("") == '""'
85+
assert quote_string('"') == r'"\""'
86+
assert quote_string(r"foo \ bar") == r'"foo \\ bar"'
87+
assert quote_string(r"foo \" bar") == r'"foo \\\" bar"'
88+
assert quote_string('a"a') == r'"a\"a"'

0 commit comments

Comments
 (0)