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

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

[elpa] externals/auctex 0dc770d 42/95: Prevent infinite loop in TeX-comm


From: Tassilo Horn
Subject: [elpa] externals/auctex 0dc770d 42/95: Prevent infinite loop in TeX-command-expand
Date: Sun, 16 Apr 2017 01:26:51 -0400 (EDT)

branch: externals/auctex
commit 0dc770d000808696879dfad60dedf82f052f46fe
Author: Mosè Giordano <address@hidden>
Commit: Mosè Giordano <address@hidden>

    Prevent infinite loop in TeX-command-expand
    
    * tex-buf.el (TeX-command-expand): Throw an error if `string' is not a 
string.
    This prevents an infinite loop.
    * tex.el (TeX-engine-in-engine-alist): New function to pick up an engine 
from
    `TeX-engine-alist' and throw an error if the engine is not there.
    (TeX-expand-list-builtin): Use `TeX-engine-in-engine-alist'.
    * context.el (ConTeXt-expand-options): Use `TeX-engine-in-engine-alist'.
    * tests/tex/command-expansion.el (TeX-command-expansion-errors): Add tests 
for
    error handling of `TeX-command-expand'.
---
 context.el                     |  2 +-
 tests/tex/command-expansion.el | 13 +++++++++++++
 tex-buf.el                     |  6 +++++-
 tex.el                         | 15 +++++++++++++--
 4 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/context.el b/context.el
index e220c43..2f302b3 100644
--- a/context.el
+++ b/context.el
@@ -1623,7 +1623,7 @@ Use `ConTeXt-Mark-version' to choose the command."
    ;; In any other case fall back on Mark II.
    (t
     (concat
-     (let ((engine (eval (nth 4 (assq TeX-engine (TeX-engine-alist))))))
+     (let ((engine (eval (nth 4 (TeX-engine-in-engine-alist TeX-engine)))))
        (when engine
         (format "--engine=%s " engine)))
      (unless (eq ConTeXt-current-interface "en")
diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index ebdb6d1..17759d1 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -33,6 +33,19 @@
                                 'TeX-master-file))
            "%%  \"\\input\"")))
 
+(ert-deftest TeX-command-expansion-errors ()
+  "Test error handling in `TeX-command-expand'."
+  (should-error
+   ;; This should prevent an infinite loop.
+   (let ((TeX-expand-list '(("%(nil)" "nil"))))
+     (TeX-command-expand "%(nil)"
+                        'TeX-master-file)))
+  (should-error
+   ;; This error is actually thrown by `TeX-engine-in-engine-alist', but we 
want
+   ;; to be sure that `TeX-command-expand' fails when the engine is not valid.
+   (let ((TeX-engine 'non-existing-engine))
+     (TeX-command-expand "%l" 'TeX-master-file))))
+
 (ert-deftest TeX-view-command-raw-errors ()
   "Tests to trigger errors in `TeX-view-command-raw'."
   ;; Viewer specification should be either a command line string or a Lisp
diff --git a/tex-buf.el b/tex-buf.el
index 6497777..b893706 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -585,7 +585,11 @@ without further expansion."
                            (error "Nonexpansion %s" expansion)))))
       (if (stringp string)
          (setq command
-               (replace-match string t t command)))))
+               (replace-match string t t command))
+       ;; If `string' is not a string, `command' will not be updated and
+       ;; `while' would enter an infinite loop.  Prevent it by throwing an
+       ;; error.
+       (error "Nonexpansion %s" expansion))))
   command)
 
 (defun TeX-check-files (derived originals extensions)
diff --git a/tex.el b/tex.el
index 11a40e0..64e5ea2 100644
--- a/tex.el
+++ b/tex.el
@@ -478,8 +478,8 @@ string."
     ("%(file-line-error)"
      (lambda () (if TeX-file-line-error " -file-line-error" "")))
     ("%(o?)" (lambda () (if (eq TeX-engine 'omega) "o" "")))
-    ("%(tex)" (lambda () (eval (nth 2 (assq TeX-engine (TeX-engine-alist))))))
-    ("%(latex)" (lambda () (eval (nth 3 (assq TeX-engine 
(TeX-engine-alist))))))
+    ("%(tex)" (lambda () (eval (nth 2 (TeX-engine-in-engine-alist 
TeX-engine)))))
+    ("%(latex)" (lambda () (eval (nth 3 (TeX-engine-in-engine-alist 
TeX-engine)))))
     ("%(cntxcom)" ConTeXt-expand-command)
     ("%(execopts)" ConTeXt-expand-options)
     ("%(extraopts)" (lambda () TeX-command-extra-options))
@@ -1664,6 +1664,17 @@ The function appends the built-in engine specs from
 where an entry with the same car exists in the user-defined part."
   (TeX-delete-dups-by-car (append TeX-engine-alist TeX-engine-alist-builtin)))
 
+(defun TeX-engine-in-engine-alist (engine)
+  "Return the `engine' entry in `TeX-engine-alist'.
+
+Throw an error if `engine' is not present in the alist."
+  (or
+   (assq engine (TeX-engine-alist))
+   (error "`%s' is not a known engine.  Valid values are: %s." engine
+         (mapconcat
+          (lambda (x) (prin1-to-string (car x)))
+          (TeX-engine-alist) ", "))))
+
 (defcustom TeX-engine 'default
   (concat "Type of TeX engine to use.
 It should be one of the following symbols:\n\n"



reply via email to

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