leonchen83/redis-rdb-cli

Hash values with control characters are not encoded properly in JSON

billcrook opened this issue · 2 comments

Describe the bug
If a hash value contains a special character, it is not encoded properly when converting to JSON. Subsequent parsing of the JSON file fails.

To Reproduce
Set a hash value with a special character such as hex 1a (control-z) utf-8.

Export the dump to JSON:
$ ./rct -f json -s backup.rdb -o dump.json

Parse the JSON using jq:
$ jq dump.json

Error:
parse error: Invalid string: control characters from U+0000 through U+001F must be escaped at line 121026, column 899

Expected behavior
The exported JSON should adhere to the JSON spec and be parseable by common tools such as jq.

Version(please run rct -v and paste the information):
java -version is less than 1.8
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8
redis rdb cli: v0.3.1 (63171da: 2020-02-29T01:47:06+0000)
rct home: /home/crook/Downloads/redis-rdb-cli/bin/..
java version: 11.0.6, vendor: Oracle Corporation
java home: /usr/lib/jvm/java-11-openjdk
default locale: en, platform encoding: UTF8
os name: Linux, version: 5.5.6-arch1-1, arch: amd64

Additional context
Example utf-8 bytes that cause the issue:

@billcrook
fixed at version v0.3.2

you can add -e option to set redis esacpe to show binary bytes.
by default -e option is raw that means use json escape to show unicode string.
for example. if your key and value contains binary bytes. use following command.

$ ./rct -f json -s backup.rdb -o dump.json -e redis

Thanks again! This is working now.