unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Michal Sojka <sojkam1@fel.cvut.cz>
To: James Westby <jw+debian@jameswestby.net>,
	notmuch@notmuchmail.org, Scott Robinson <scott@quadhome.com>
Subject: [PATCH] Fix invalid JSON output for NULL strings
Date: Sun, 14 Mar 2010 21:44:18 +0100	[thread overview]
Message-ID: <87ociqzl99.fsf@steelpick.localdomain> (raw)
In-Reply-To: <87ociqbud3.fsf@jameswestby.net>

On Sun, 14 Mar 2010 15:01:28 -0400, James Westby <jw+debian@jameswestby.net> wrote:
> On Sun, 14 Mar 2010 19:19:11 +0100, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> > Mails with empty body produced the following output:
> >   "body": [{"id": 1, "content-type": "text/plain", "content": (null)}]
> > The (null) is not valid JSON syntax.
> 
> Is this just something that can happen with the body?
> 
> I've see (null) in the emacs interface when I've done something silly
> such as opening a newer notmuch db with an old client.
> 
> Should all the attributes be guarded in a similar manner to ensure valid
> JSON?


You're right. When you import messages from mail archive such as
http://notmuchmail.org/pipermail/notmuch/, there are no To: headers.
This case is already handled by the current code, but what about this
more universal solution? It also solves my problem with notmuchsynch.

-- >8 --
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 json.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/json.c b/json.c
index 9614143..0885d3d 100644
--- a/json.c
+++ b/json.c
@@ -56,7 +56,7 @@ json_quote_str(const void *ctx, const char *str)
     int len = 0;
 
     if (!str)
-	return NULL;
+	return (char*)"null";
 
     for (ptr = str; *ptr; len++, ptr++) {
 	if (*ptr < 32 || *ptr == '\"' || *ptr == '\\')
-- 
1.7.0

  reply	other threads:[~2010-03-14 20:44 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-11 15:25 Notmuch command interface Ben Gamari
2010-03-11 22:52 ` David A Benjamin
2010-03-12  0:52   ` Ben Gamari
2010-03-12  8:31   ` Michal Sojka
2010-03-12 14:46     ` Sebastian Spaeth
2010-03-12 15:03       ` Michal Sojka
2010-03-12 16:03         ` Sebastian Spaeth
2010-03-14 18:15           ` Michal Sojka
2010-03-14 18:19             ` [PATCH] Produce valid JSON output even if mail body is empty Michal Sojka
2010-03-14 19:01               ` James Westby
2010-03-14 20:44                 ` Michal Sojka [this message]
2010-03-12  9:18   ` Notmuch command interface Sebastian Spaeth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ociqzl99.fsf@steelpick.localdomain \
    --to=sojkam1@fel.cvut.cz \
    --cc=jw+debian@jameswestby.net \
    --cc=notmuch@notmuchmail.org \
    --cc=scott@quadhome.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).