diff options
author | Andy McCurdy <andy@andymccurdy.com> | 2020-06-08 12:58:25 -0700 |
---|---|---|
committer | Andy McCurdy <andy@andymccurdy.com> | 2020-06-08 12:58:25 -0700 |
commit | 7e466f7bee41d88e01d22e3a4c904e0e578630c9 (patch) | |
tree | c6036ee937f3672dc3dbfdb62397a51a377bdc8e | |
parent | 2c9f41f46991f94f0626598600d1023d4e12f0bc (diff) | |
download | redis-py-7e466f7bee41d88e01d22e3a4c904e0e578630c9.tar.gz |
Do not un-escape \ characters when parsing MONITOR output
Prior to this, escaped slashes ("\\") were un-escaped. This caused the strings
"foo\x92" and "foo\\x92" to be represented the same way in the output.
Fixes #1349
-rwxr-xr-x | redis/client.py | 5 | ||||
-rw-r--r-- | tests/test_monitor.py | 7 |
2 files changed, 11 insertions, 1 deletions
diff --git a/redis/client.py b/redis/client.py index 3471895..5cf778c 100755 --- a/redis/client.py +++ b/redis/client.py @@ -3344,7 +3344,10 @@ class Monitor(object): m = self.monitor_re.match(command_data) db_id, client_info, command = m.groups() command = ' '.join(self.command_re.findall(command)) - command = command.replace('\\"', '"').replace('\\\\', '\\') + # Redis escapes double quotes because each piece of the command + # string is surrounded by double quotes. We don't have that + # requirement so remove the escaping and leave the quote. + command = command.replace('\\"', '"') if client_info == 'lua': client_address = 'lua' diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 0e39ec0..ee5dc6e 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -34,6 +34,13 @@ class TestMonitor(object): response = wait_for_command(r, m, 'GET foo\\x92') assert response['command'] == 'GET foo\\x92' + def test_command_with_escaped_data(self, r): + with r.monitor() as m: + byte_string = b'foo\\x92' + r.get(byte_string) + response = wait_for_command(r, m, 'GET foo\\\\x92') + assert response['command'] == 'GET foo\\\\x92' + def test_lua_script(self, r): with r.monitor() as m: script = 'return redis.call("GET", "foo")' |