emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/org 4ff4828944 2/2: org-footnote--collect-references: F


From: ELPA Syncer
Subject: [elpa] externals/org 4ff4828944 2/2: org-footnote--collect-references: Fix infinite recursion
Date: Sat, 23 Nov 2024 15:58:26 -0500 (EST)

branch: externals/org
commit 4ff482894425c14bb278745e8d71e2c532a2e37e
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>

    org-footnote--collect-references: Fix infinite recursion
    
    * lisp/org-footnote.el (org-footnote--collect-references): Fix
    infinite recursion when nested references form a closed loop.
    * testing/lisp/test-org-footnote.el (test-org-footnote/sort): New
    test.
    
    Reported-by: Avraham Pinkas <ampinkas@gmail.com>
    Link: 
https://orgmode.org/list/CAHEwkt8vnYGr1ZN-De9ec4bqBk_7yHARFAsZmY81u1GimSritA@mail.gmail.com
---
 lisp/org-footnote.el              |  3 ++-
 testing/lisp/test-org-footnote.el | 20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/lisp/org-footnote.el b/lisp/org-footnote.el
index 64037deb25..36bffdbfc8 100644
--- a/lisp/org-footnote.el
+++ b/lisp/org-footnote.el
@@ -404,7 +404,8 @@ References are sorted according to a deep-reading order."
                   (dolist (r (mapcar (lambda (l) (assoc l references))
                                      (reverse
                                       (cdr (assoc (nth 0 ref) nested)))))
-                    (funcall add-reference r t))))))
+                     (unless (member r ordered) ; avoid infinite recursion 
when references link to each other
+                      (funcall add-reference r t)))))))
        (dolist (r (reverse references) (nreverse ordered))
         (funcall add-reference r nil))))))
 
diff --git a/testing/lisp/test-org-footnote.el 
b/testing/lisp/test-org-footnote.el
index 21f6ae8842..0d7a93ce45 100644
--- a/testing/lisp/test-org-footnote.el
+++ b/testing/lisp/test-org-footnote.el
@@ -533,6 +533,26 @@ Text[fn:1][fn:4]
 \[fn:2] Def 2[fn:3]
 
 \[fn:4] Def 4
+"
+      (let ((org-footnote-section nil)) (org-footnote-sort))
+      (buffer-string))))
+  ;; Handle cycles inside nested references
+  (should
+   (equal
+    "
+One [fn:2] two [fn:1]
+
+[fn:2] Two [fn:1]
+
+[fn:1] One [fn:2]
+"
+    (org-test-with-temp-text
+       "
+One [fn:2] two [fn:1]
+
+[fn:1] One [fn:2]
+
+[fn:2] Two [fn:1]
 "
       (let ((org-footnote-section nil)) (org-footnote-sort))
       (buffer-string))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]