summaryrefslogtreecommitdiff
path: root/src/data_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/data_string.c')
-rw-r--r--src/data_string.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/data_string.c b/src/data_string.c
index 5b2678d8..a4bc31cf 100644
--- a/src/data_string.c
+++ b/src/data_string.c
@@ -70,8 +70,25 @@ static int data_response_insert_dup(data_unset *dst, data_unset *src) {
static void data_string_print(const data_unset *d, int depth) {
data_string *ds = (data_string *)d;
UNUSED(depth);
+ unsigned int i = 0;
- fprintf(stdout, "\"%s\"", ds->value->used ? ds->value->ptr : "");
+ // empty and uninitialized strings
+ if (ds->value->used < 1) {
+ fputs("\"\"", stdout);
+ return;
+ }
+
+ // print out the string as is, except prepend " with backslash
+ putc('"', stdout);
+ for (i = 0; i < ds->value->used - 1; i++) {
+ unsigned char c = ds->value->ptr[i];
+ if (c == '"') {
+ fputs("\\\"", stdout);
+ } else {
+ putc(c, stdout);
+ }
+ }
+ putc('"', stdout);
}