]> pd.if.org Git - zpackage/commitdiff
quote json note output
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 9 Dec 2018 16:39:41 +0000 (16:39 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 9 Dec 2018 16:39:41 +0000 (16:39 +0000)
zpm-note.c

index c94e37b480295cb65f5e06227dfcc171d3424a1c..d6c9df1e5ffff8eccd7087481f93887a80f54149 100644 (file)
@@ -18,6 +18,9 @@ void show_note(struct zpm_note *n) {
        if (n->pkgid) {
                printf("Package: %s\n", n->pkgid);
        }
+       if (n->path) {
+               printf("Path: %s\n", n->pkgid);
+       }
        if (n->file) {
                printf("Hash: %s\n", n->file);
        }
@@ -31,7 +34,12 @@ void jstring(char *field, char *value, int indent, int final) {
        }
        printf("\"%s\": ", field);
        if (value) {
-               printf("\"%s\": ", value);
+               while (*value) {
+                       if (strchr("\"\\\b\f\n\r\t", *value)) {
+                               putchar('\\');
+                       }
+                       putchar(*value++);
+               }
        } else {
                printf("null");
        }
@@ -51,6 +59,7 @@ void show_json(struct zpm_note *n) {
        printf("{\n\t\"id\": %" PRId64 ",\n", n->id);
        jstring("package", n->pkgid, 1, 0);
        jstring("hash", n->file, 1, 0);
+       jstring("path", n->path, 1, 0);
 
        if (len) {
                printf("\t\"subject\": \"%.*s\",\n", (int)len, n->note);