From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id UKg3Agv/X2JwNwEAbAwnHQ (envelope-from ) for ; Wed, 20 Apr 2022 14:39:39 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id httGAgv/X2K7yAAA9RJhRA (envelope-from ) for ; Wed, 20 Apr 2022 14:39:39 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7C68C281E6 for ; Wed, 20 Apr 2022 14:39:38 +0200 (CEST) Received: from localhost ([::1]:47046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nh9cP-0008CM-6i for larch@yhetil.org; Wed, 20 Apr 2022 08:39:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55076) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nh9bC-0008Bs-Q0 for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 08:38:22 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]:38750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nh9bB-0003Dw-1s for emacs-orgmode@gnu.org; Wed, 20 Apr 2022 08:38:22 -0400 Received: by mail-wm1-x336.google.com with SMTP id r187-20020a1c44c4000000b0038ccb70e239so3580411wma.3 for ; Wed, 20 Apr 2022 05:38:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=7l0pygHbLJEcG4wR0nGT0Ld2tAOTTzSsW4h1/LqhHPM=; b=I2z1Xxtny0FYikzSPGO0sNClTRXWEwMyxu1x0MlNJD0hAzZavu88THDpWcaSEpgshp SVGZJuR6+o2ivSrFAPgfIg7PAYvh63CGkYZcH74qHwtlwj2xbkB7e066WaX85gf93n8S uJbKZis1YOClgPcr9Dbnjo+C8wZnmSeXlMT2cQNW7Dk3NcR4GgwLm5aY6RJBwhXTTAkS B+vADnM11uTYxQCXNmAlTiRmFUJ56e4co5POWo4KDt5/xgUj5l20Qhk5t0ErxKp/hQyQ +N+q/dg5/B0fpLkRWc8qWvfC5m0HAIFPulghmWZEshG8GrgsI16TCOGKB515z7zyDQP0 AmKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=7l0pygHbLJEcG4wR0nGT0Ld2tAOTTzSsW4h1/LqhHPM=; b=KuYCt3gz6kxxIpgqZCCPYxH5q5T4Is/AAo3QXTXRwxWCpmVSOavDP4x//WhSDsNzKd ZpxO6uZH8o6q57tHSXuFDkMfWtqdjZzmYYsBI2z4LM0x4CNnxWKG04ZlZKUEvNoPjf2w FzQEpn3Ro0bLr6Q2z8FHdVMhafOvVQugT+JryS4RbAJxS15ZFjuPuLdFwaFXsX9voxzS e/QAy1ZNWdheArZut0MqKY/CNdafu9I81t+tMAeVH95a4ziPeWh/T+eK5znVzkjDNuz9 vIFnPFgsyGPP3I2csAQKsT5Wv0SVae5LNa72W1xWR2XMailFc+NL5K4xw6am3h7i13yF CH7w== X-Gm-Message-State: AOAM532Zi0KpZyzo5DBBwvW8Sot98EU9DVGtEnS3vWCnh7vk7mXDBlxq 6q0Mz3k1yW6bU/h8uKFhmN8YkafonSwBfyzPLNH+fGjr2CA= X-Google-Smtp-Source: ABdhPJwpPBQCcaSe5XxypI/A6PJ9NrjEcduKID7ujarrW5gGAkA/dBVqJF8spbFzaO8XDWmpE4psXoOizZEpJWgx7H4= X-Received: by 2002:a05:600c:1908:b0:391:7786:9ba0 with SMTP id j8-20020a05600c190800b0039177869ba0mr3586744wmq.145.1650458298782; Wed, 20 Apr 2022 05:38:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: "Bruce D'Arcus" Date: Wed, 20 Apr 2022 08:38:27 -0400 Message-ID: Subject: Re: [PATCH] oc-basic: Detect malformed bibtex bibliographies To: org-mode-email Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=bdarcus@gmail.com; helo=mail-wm1-x336.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1650458378; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=7l0pygHbLJEcG4wR0nGT0Ld2tAOTTzSsW4h1/LqhHPM=; b=q2LQvHIkl/JxkO84cZFODNP1P1X6JqVaI8iR5dmVEYKDeqqR1qeHgFM5M+ldX75VJsFbDF 5KVi+iN1s+6Ud8PFUi5eLFm819Yqk7z78wxwQBwf5OZdBtgJrxnUOsTeffPufI3ckprRGp TT6I9Ke73ha+riGqsCya7Hb2kpguwK227B1TCIE7eyAAbQlXa+yzXknVNGZxzbdEN4ApAh FD07Wjf2SLaGYM5cKp6R6C8z4oDJEQhVYWj6QREMDjta2ENiTQ576Z75vp8/vZhqQIrnpU 2BeifZw9lxtnpiZ1Ggdnn0mH2emKZySIwZ0k3XILi7nARWlwvb6C21f3dH0hew== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1650458378; a=rsa-sha256; cv=none; b=Z4RPJk1n7QWxur1WaZmn144ujCpb4vL3KaL5jT8QDNxj5dRRIW89Qf20lreNuXy45iNNS/ /22QwhQnqM5d9f+2zquWAQq1fAbhOItCNfom+vgixXyNgaXeZvkm+bh6kie9QT8J2S8C7j srq6uPKzmBxxZ2kjIirfe5ecoB3fdFvYicsO1Z0Y3bYnTELdZaM2z5jE/5CBIgniMBLjki 5YbTu0IT3a+Vm8KAhA6I/rStUEFXiPQiYXaCP93+u2gprt4coXyL1ywKz/IKADVT6qdLXy XYTxtDV7elldiVnpYryDp+pVm4xgwR3HnZXfQq+nFpJ0KLO3EFQN6vmyMJ20yQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=I2z1Xxtn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -4.04 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=I2z1Xxtn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 7C68C281E6 X-Spam-Score: -4.04 X-Migadu-Scanner: scn1.migadu.com X-TUID: FfIvJaVsd5Gq On Wed, Apr 20, 2022 at 8:28 AM Ihor Radchenko wrote: > > There is an edge case triggering infinite loop in oc-basic. > > It is caused by bibtex-map-entries (used in > org-cite-basic--parse-bibtex) when ran on a malformed bibtex buffer [1]. > > The proposed patch validates the bibtex buffer before processing and > throws an error if issues are found. `bibtex-validate` also > conveniently displays a list of errors with clickable links to > problematic lines. > > I believe that it is useful for the users to see such issues instead of, > say, failing silently on malformed bibliographies. > > WDYT? I haven't tested it, but this is an excellent idea! Bruce > Best, > Ihor > > [1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=55036 > > * lisp/oc-basic.el (org-cite-basic--parse-bibtex): Validate the > bibliography before parsing. Display list of issues if any (via > `bibtex-validate`). > (org-cite-basic--parse-bibliography): Set buffer file name needed by > `bibtex-validate`. Empty the cache in case of error. > --- > lisp/oc-basic.el | 38 ++++++++++++++++++++++++-------------- > 1 file changed, 24 insertions(+), 14 deletions(-) > > diff --git a/lisp/oc-basic.el b/lisp/oc-basic.el > index 873986d07..79f7a4844 100644 > --- a/lisp/oc-basic.el > +++ b/lisp/oc-basic.el > @@ -214,6 +214,10 @@ (defun org-cite-basic--parse-bibtex (dialect) > (let ((entries (make-hash-table :test #'equal)) > (bibtex-sort-ignore-string-entries t)) > (bibtex-set-dialect dialect t) > + ;; Throw an error if bibliography is malformed. > + (unless (bibtex-validate) > + (user-error "Malformed bibliography at %S" > + (or (buffer-file-name) (current-buffer)))) > (bibtex-map-entries > (lambda (key &rest _) > ;; Normalize entries: field names are turned into symbols > @@ -258,21 +262,27 @@ (defun org-cite-basic--parse-bibliography (&optional info) > (when (or (org-file-has-changed-p file) > (not (gethash file org-cite-basic--file-id-cache))) > (insert-file-contents file) > + (setf (buffer-file-name) file) > (puthash file (org-buffer-hash) org-cite-basic--file-id-cache)) > - (let* ((file-id (cons file (gethash file org-cite-basic--file-id-cache))) > - (entries > - (or (cdr (assoc file-id org-cite-basic--bibliography-cache)) > - (let ((table > - (pcase (file-name-extension file) > - ("json" (org-cite-basic--parse-json)) > - ("bib" (org-cite-basic--parse-bibtex 'biblatex)) > - ("bibtex" (org-cite-basic--parse-bibtex 'BibTeX)) > - (ext > - (user-error "Unknown bibliography extension: %S" > - ext))))) > - (push (cons file-id table) org-cite-basic--bibliography-cache) > - table)))) > - (push (cons file entries) results))))) > + (unwind-protect > + (condition-case nil > + (unwind-protect > + (let* ((file-id (cons file (gethash file org-cite-basic--file-id-cache))) > + (entries > + (or (cdr (assoc file-id org-cite-basic--bibliography-cache)) > + (let ((table > + (pcase (file-name-extension file) > + ("json" (org-cite-basic--parse-json)) > + ("bib" (org-cite-basic--parse-bibtex 'biblatex)) > + ("bibtex" (org-cite-basic--parse-bibtex 'BibTeX)) > + (ext > + (user-error "Unknown bibliography extension: %S" > + ext))))) > + (push (cons file-id table) org-cite-basic--bibliography-cache) > + table)))) > + (push (cons file entries) results)) > + (setf (buffer-file-name) nil)) > + (error (setq org-cite-basic--file-id-cache nil))))))) > (when info (plist-put info :cite-basic/bibliography results)) > results))) > > -- > 2.35.1 > > > > -- > Ihor Radchenko, > PhD, > Center for Advancing Materials Performance from the Nanoscale (CAMP-nano) > State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong University, Xi'an, China > Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg >