summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan <59206115+Threated@users.noreply.github.com>2023-01-11 10:19:29 +0100
committerGitHub <noreply@github.com>2023-01-11 11:19:29 +0200
commit4a825bc76b668951923c57aaff1020c3892f8de2 (patch)
treef39c9cfcf22579f9242df20757ad358e417f25a4
parentf46d7f3ef7ce64f90acd4a3dcc14375ab9ae9c9d (diff)
downloadredis-py-4a825bc76b668951923c57aaff1020c3892f8de2.tar.gz
String cleanse (#2548)
* Fixed string escape and added tests * Add Change * Name change
-rw-r--r--CHANGES1
-rw-r--r--redis/commands/helpers.py1
-rw-r--r--tests/test_graph.py2
-rw-r--r--tests/test_helpers.py6
4 files changed, 9 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index fca8d31..02daf5e 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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)
diff --git a/redis/commands/helpers.py b/redis/commands/helpers.py
index 6989ab5..b65cd1a 100644
--- a/redis/commands/helpers.py
+++ b/redis/commands/helpers.py
@@ -115,6 +115,7 @@ def quote_string(v):
if len(v) == 0:
return '""'
+ v = v.replace("\\", "\\\\")
v = v.replace('"', '\\"')
return f'"{v}"'
diff --git a/tests/test_graph.py b/tests/test_graph.py
index d71df48..4721b2f 100644
--- a/tests/test_graph.py
+++ b/tests/test_graph.py
@@ -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})
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 3595829..57a94d2 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -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"'