[PATCH] emacs: Fix bug in resynchronizing after a JSON parse error
authorAustin Clements <amdragon@MIT.EDU>
Fri, 14 Dec 2012 15:07:35 +0000 (10:07 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:52:11 +0000 (09:52 -0800)
d5/5156ec7e199f93302ef44b7821566b806dad61 [new file with mode: 0644]

diff --git a/d5/5156ec7e199f93302ef44b7821566b806dad61 b/d5/5156ec7e199f93302ef44b7821566b806dad61
new file mode 100644 (file)
index 0000000..eb212ec
--- /dev/null
@@ -0,0 +1,129 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id F1169431FBC\r
+       for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 07:07:45 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id qlFVZSK6DeBd for <notmuch@notmuchmail.org>;\r
+       Fri, 14 Dec 2012 07:07:45 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3DDDD431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 14 Dec 2012 07:07:45 -0800 (PST)\r
+X-AuditID: 12074423-b7fcb6d000000927-62-50cb40c03613\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id F6.7A.02343.0C04BC05; Fri, 14 Dec 2012 10:07:44 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id qBEF7f7J028839; \r
+       Fri, 14 Dec 2012 10:07:41 -0500\r
+Received: from drake.dyndns.org\r
+       (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [209.6.116.242]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id qBEF7dWW002260\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 14 Dec 2012 10:07:40 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TjWrS-0002Ym-Bg; Fri, 14 Dec 2012 10:07:38 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error\r
+Date: Fri, 14 Dec 2012 10:07:35 -0500\r
+Message-Id: <1355497655-9571-1-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrCIsWRmVeSWpSXmKPExsUixG6nonvA4XSAwcOTRhar5/JYXL85k9mB\r
+       yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyvjyfB5jwWShisuX7jA1MF7l62Lk5JAQMJG4\r
+       Mfk3G4QtJnHh3nowW0hgH6PE+7maXYxcQPYGRolL/yYxQTiPmCS+bpnEDuHMZZS4vOw6O0gL\r
+       m4CGxLb9yxlBbBEBaYmdd2ezgtjMAo4Sn/cvAhsrLOAtcWL3NWYQm0VAVeLH24dMIDavgL3E\r
+       5Pl7GCHOUJTofjaBbQIj7wJGhlWMsim5Vbq5iZk5xanJusXJiXl5qUW6Znq5mSV6qSmlmxjB\r
+       geGivIPxz0GlQ4wCHIxKPLwTOE8FCLEmlhVX5h5ilORgUhLlbbI5HSDEl5SfUpmRWJwRX1Sa\r
+       k1p8iFGCg1lJhJdVHSjHm5JYWZValA+TkuZgURLnvZZy019IID2xJDU7NbUgtQgmK8PBoSTB\r
+       e9UeqFGwKDU9tSItM6cEIc3EwQkynAdo+AeQGt7igsTc4sx0iPwpRkUpcd7jIAkBkERGaR5c\r
+       LyxyXzGKA70izPsWpIoHGPVw3a+ABjMBDY67dBxkcEkiQkqqgdFkZ1GQyue3vB6K+/8dEuyz\r
+       +hZVe4klqOv3nil3mR6svSP3R9/BvCSv23La8Y77ERunr9LtPRtjuXnj+43f2I/supCV3Hbr\r
+       p4qlenW/34yXJabW53d63/7An8Tb7Vi5ls9TzkjS82jPqqVLLrdsMXgkxbD0Zeyz8+cOzT2v\r
+       e3anwJeVsiGbyyYqsRRnJBpqMRcVJwIA5bJiJLcCAAA=\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 14 Dec 2012 15:07:46 -0000\r
+\r
+Previously, if the input stream consisted only of an error message,\r
+notmuch-json-begin-compound would signal a (wrong-type-argument\r
+number-or-marker-p nil) error when reaching the end of the error\r
+message.  This happened because notmuch-json-scan-to-value would think\r
+that it reached a value and put the parser into the 'value state.\r
+Even after notmuch-json-begin-compound signaled the syntax error, the\r
+parser would remain in this state and when the resynchronization logic\r
+reached the end of the buffer, the parser would fail because the\r
+'value state indicates that characters are available.\r
+\r
+This fixes this problem by restoring the parser's previous state if it\r
+encounters a syntax error.\r
+---\r
+\r
+This patch was already okayed by Mark Walters [0] in the context of a\r
+larger series.  Since it's independent of that larger series, I'm\r
+re-sending it separately.\r
+\r
+[0] id:87hanxgczt.fsf@qmul.ac.uk\r
+\r
+ emacs/notmuch-lib.el |   22 +++++++++++++---------\r
+ 1 file changed, 13 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index 9c4ee71..fb6d3e7 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -465,15 +465,19 @@ Entering JSON objects is currently unimplemented."\r
+   (with-current-buffer (notmuch-json-buffer jp)\r
+     ;; Disallow terminators\r
+     (setf (notmuch-json-allow-term jp) nil)\r
+-    (or (notmuch-json-scan-to-value jp)\r
+-      (if (/= (char-after) ?\[)\r
+-          (signal 'json-readtable-error (list "expected '['"))\r
+-        (forward-char)\r
+-        (push ?\] (notmuch-json-term-stack jp))\r
+-        ;; Expect a value or terminator next\r
+-        (setf (notmuch-json-next jp) 'expect-value\r
+-              (notmuch-json-allow-term jp) t)\r
+-        t))))\r
++    ;; Save "next" so we can restore it if there's a syntax error\r
++    (let ((saved-next (notmuch-json-next jp)))\r
++      (or (notmuch-json-scan-to-value jp)\r
++        (if (/= (char-after) ?\[)\r
++            (progn\r
++              (setf (notmuch-json-next jp) saved-next)\r
++              (signal 'json-readtable-error (list "expected '['")))\r
++          (forward-char)\r
++          (push ?\] (notmuch-json-term-stack jp))\r
++          ;; Expect a value or terminator next\r
++          (setf (notmuch-json-next jp) 'expect-value\r
++                (notmuch-json-allow-term jp) t)\r
++          t)))))\r
\r
+ (defun notmuch-json-read (jp)\r
+   "Parse the value at point in JP's buffer.\r
+-- \r
+1.7.10.4\r
+\r