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

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

[elpa] elpa d418e9a 15/51: Prevent infinite loop in TeX-command-expand


From: Tassilo Horn
Subject: [elpa] elpa d418e9a 15/51: Prevent infinite loop in TeX-command-expand
Date: Sun, 22 May 2016 07:22:48 +0000 (UTC)

branch: elpa
commit d418e9a064e4158556dacb33744d610097eff04b
Author: Mosè Giordano <address@hidden>
Commit: Mosè Giordano <address@hidden>

    Prevent infinite loop in TeX-command-expand
    
    * tex.el (TeX-view-command-raw): This function should always return a
      string.  Throw an error if fails to do so.  This prevents an infinite
      loop in `TeX-command-expand' in the case in which `command' is nil
      because of a malformed viewer specification.
    * tests/tex/command-expansion.el (TeX-view-command-raw-errors): Add
      tests to trigger errors in `TeX-view-command-raw'.
---
 tests/tex/command-expansion.el |   43 ++++++++++++++++++++++++++++++++++++++++
 tex.el                         |    6 +++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/tests/tex/command-expansion.el b/tests/tex/command-expansion.el
index d6dfc89..ebdb6d1 100644
--- a/tests/tex/command-expansion.el
+++ b/tests/tex/command-expansion.el
@@ -33,4 +33,47 @@
                                 'TeX-master-file))
            "%%  \"\\input\"")))
 
+(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
+  ;; function name to be executed.  This test makes sure that the functions
+  ;; throws an error if the selected viewer has a wrong specification (for
+  ;; example a function call, not the function name) such that the returned
+  ;; value `command' isn't a string.  This prevents an infinite loop in
+  ;; `TeX-command-expand'.
+  (should-error
+   (with-temp-buffer
+     (let ((TeX-view-program-list '(("viewer"
+                                    (wrong-specification))))
+          (TeX-view-program-selection
+           '((output-pdf "viewer"))))
+       (TeX-mode)
+       (TeX-view-command-raw)))
+   :type 'error)
+  ;; Signal an error when a nonexistent viewer is selected.
+  (should-error
+   (with-temp-buffer
+     (let ((TeX-view-program-selection
+           '((output-pdf "does-not-exist"))))
+       (TeX-mode)
+       (TeX-view-command-raw)))
+   :type 'error)
+  ;; Signal an error if the binary associated to the viewer cannot be found.
+  (should-error
+   (with-temp-buffer
+     (let ((TeX-view-program-list
+           '(("viewer" "viewer %o" "**this-program-does-not-exist**")))
+          (TeX-view-program-selection
+           '((output-pdf "viewer"))))
+       (TeX-mode)
+       (TeX-view-command-raw)))
+   :type 'error)
+  ;; Error if there is no selected viewer for current buffer.
+  (should-error
+   (with-temp-buffer
+     (let (TeX-view-program-selection)
+       (TeX-mode)
+       (TeX-view-command-raw)))
+   :type 'error))
+
 ;;; command-expansion.el ends here
diff --git a/tex.el b/tex.el
index f7b5bc4..fb734f4 100644
--- a/tex.el
+++ b/tex.el
@@ -1598,7 +1598,11 @@ Check the `TeX-view-program-selection' variable" 
viewer)))
                   ((listp elt)
                    (when (TeX-view-match-predicate (car elt))
                      (setq command (concat command (cadr elt)))))))
-          command))))
+          (if (stringp command)
+              command
+            ;; Signal an error if `command' isn't a string.  This prevents an
+            ;; infinite loop in `TeX-command-expand' if `command' is nil.
+            (error "Wrong viewer specification in 
`TeX-view-program-list'"))))))
 
 ;;; Engine
 



reply via email to

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