Skip to content

Commit

Permalink
String cleanse (#2548)
Browse files Browse the repository at this point in the history
* Fixed string escape and added tests

* Add Change

* Name change
  • Loading branch information
Threated committed Jan 11, 2023
1 parent f46d7f3 commit 4a825bc
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* Fix string cleanse in Redis Graph
* Make PythonParser resumable in case of error (#2510)
* Add `timeout=None` in `SentinelConnectionManager.read_response`
* Documentation fix: password protected socket connection (#2374)
Expand Down
1 change: 1 addition & 0 deletions redis/commands/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def quote_string(v):
if len(v) == 0:
return '""'

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

return f'"{v}"'
Expand Down
2 changes: 1 addition & 1 deletion tests/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def test_path(client):

@pytest.mark.redismod
def test_param(client):
params = [1, 2.3, "str", True, False, None, [0, 1, 2]]
params = [1, 2.3, "str", True, False, None, [0, 1, 2], r"\" RETURN 1337 //"]
query = "RETURN $param"
for param in params:
result = client.graph().query(query, {"param": param})
Expand Down
6 changes: 6 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ def test_quote_string():
assert quote_string("hello world!") == '"hello world!"'
assert quote_string("") == '""'
assert quote_string("hello world!") == '"hello world!"'
assert quote_string("abc") == '"abc"'
assert quote_string("") == '""'
assert quote_string('"') == r'"\""'
assert quote_string(r"foo \ bar") == r'"foo \\ bar"'
assert quote_string(r"foo \" bar") == r'"foo \\\" bar"'
assert quote_string('a"a') == r'"a\"a"'

0 comments on commit 4a825bc

Please sign in to comment.