[PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse error
authorAustin Clements <amdragon@MIT.EDU>
Sun, 2 Dec 2012 02:39:58 +0000 (21:39 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:51:18 +0000 (09:51 -0800)
d6/bbc3a6066c8ae9ee11c0206cc69b62893413aa [new file with mode: 0644]

diff --git a/d6/bbc3a6066c8ae9ee11c0206cc69b62893413aa b/d6/bbc3a6066c8ae9ee11c0206cc69b62893413aa
new file mode 100644 (file)
index 0000000..ee8a81d
--- /dev/null
@@ -0,0 +1,125 @@
+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 26198431FAF\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Dec 2012 18:40:35 -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 FFJERYebJdiz for <notmuch@notmuchmail.org>;\r
+       Sat,  1 Dec 2012 18:40:33 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU\r
+       [18.9.25.15])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1F26F429E3B\r
+       for <notmuch@notmuchmail.org>; Sat,  1 Dec 2012 18:40:22 -0800 (PST)\r
+X-AuditID: 1209190f-b7fec6d00000090d-9b-50babf96250a\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+       by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 50.06.02317.69FBAB05; Sat,  1 Dec 2012 21:40:22 -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 qB22eC44019892; \r
+       Sat, 1 Dec 2012 21:40:12 -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 qB22e6rt025600\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sat, 1 Dec 2012 21:40:10 -0500 (EST)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1TezTS-0000xe-0h; Sat, 01 Dec 2012 21:40:06 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 06/10] emacs: Fix bug in resynchronizing after a JSON parse\r
+       error\r
+Date: Sat,  1 Dec 2012 21:39:58 -0500\r
+Message-Id: <1354416002-3557-6-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1354416002-3557-1-git-send-email-amdragon@mit.edu>\r
+References: <1354416002-3557-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nojtt/64Ag0nnZC2u35zJ7MDo8WzV\r
+       LeYAxigum5TUnMyy1CJ9uwSujJ+LPzIXHBOoWL3iFmMD4wbeLkZODgkBE4l/b7tYIWwxiQv3\r
+       1rN1MXJxCAnsY5SY+6+fFcJZzyix4cIxZpAqIYGHTBJLDxdCJOYySnxc/QIswSagIbFt/3JG\r
+       EFtEQFpi593ZQN0cHMwCahJ/ulRAwsICgRIrVz4F28YioCpxdeZvsFZeAXuJC03zGSGuUJTo\r
+       fjaBDaSVU8BBYkU3D8Rae4n/v6+xTWDkX8DIsIpRNiW3Sjc3MTOnODVZtzg5MS8vtUjXRC83\r
+       s0QvNaV0EyMoZDgl+XcwfjuodIhRgINRiYeXcdauACHWxLLiytxDjJIcTEqivFd2AIX4kvJT\r
+       KjMSizPii0pzUosPMUpwMCuJ8LKYAOV4UxIrq1KL8mFS0hwsSuK8V1Nu+gsJpCeWpGanphak\r
+       FsFkZTg4lCR4q/cBNQoWpaanVqRl5pQgpJk4OEGG8wANf7QXZHhxQWJucWY6RP4Uo6KUOO81\r
+       kIQASCKjNA+uFxbTrxjFgV4R5vUEWcEDTAdw3a+ABjMBDX6zbDvI4JJEhJRUA+PE/IqwG8wH\r
+       jIzyjGs63/hW1m+2Z1+Zc4rVLquH89fLJRNPcigsqV52uZ75C7fqyjNGkZ+utBZXna5a7cFv\r
+       qXdv6oScNek38yd7evALf6y+K/FmZfTEBWbOgXd/257nZRPO2NGQwvp2V5PVpTMHsxvDrznX\r
+       5NmvvdD+IfuUv5X7hqU/Nxq/UFdiKc5INNRiLipOBAAkaR7vxAIAAA==\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: Sun, 02 Dec 2012 02:40:35 -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
+ 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 1d0ec17..9402456 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -474,15 +474,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