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