summaryrefslogtreecommitdiff
path: root/src/cli_common.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2022-04-05 14:25:02 +0300
committerGitHub <noreply@github.com>2022-04-05 14:25:02 +0300
commitfb4e0d400ff82117104bde5296c477ad95f8dd41 (patch)
tree4ede2d02b134a84ff29bb7398902c398cd4ff454 /src/cli_common.c
parentd2b5a579dd8b785690aa7714df8776ffc452d242 (diff)
parent8b242ef977b88d6cae38d451130a88116bcbb638 (diff)
downloadredis-7.0-rc3.tar.gz
Merge pull request #10532 from oranagra/7.0-rc37.0-rc3
Release 7.0 rc3
Diffstat (limited to 'src/cli_common.c')
-rw-r--r--src/cli_common.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/cli_common.c b/src/cli_common.c
index 7064a096b..33069017b 100644
--- a/src/cli_common.c
+++ b/src/cli_common.c
@@ -299,7 +299,7 @@ static sds percentDecode(const char *pe, size_t len) {
}
/* Parse a URI and extract the server connection information.
- * URI scheme is based on the the provisional specification[1] excluding support
+ * URI scheme is based on the provisional specification[1] excluding support
* for query parameters. Valid URIs are:
* scheme: "redis://"
* authority: [[<username> ":"] <password> "@"] [<hostname> [":" <port>]]
@@ -371,3 +371,28 @@ void freeCliConnInfo(cliConnInfo connInfo){
if (connInfo.auth) sdsfree(connInfo.auth);
if (connInfo.user) sdsfree(connInfo.user);
}
+
+/*
+ * Escape a Unicode string for JSON output (--json), following RFC 7159:
+ * https://datatracker.ietf.org/doc/html/rfc7159#section-7
+*/
+sds escapeJsonString(sds s, const char *p, size_t len) {
+ s = sdscatlen(s,"\"",1);
+ while(len--) {
+ switch(*p) {
+ case '\\':
+ case '"':
+ s = sdscatprintf(s,"\\%c",*p);
+ break;
+ case '\n': s = sdscatlen(s,"\\n",2); break;
+ case '\f': s = sdscatlen(s,"\\f",2); break;
+ case '\r': s = sdscatlen(s,"\\r",2); break;
+ case '\t': s = sdscatlen(s,"\\t",2); break;
+ case '\b': s = sdscatlen(s,"\\b",2); break;
+ default:
+ s = sdscatprintf(s,(*p >= 0 && *p <= 0x1f) ? "\\u%04x" : "%c",*p);
+ }
+ p++;
+ }
+ return sdscatlen(s,"\"",1);
+}