]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix infloop in 'shell-resync-dirs'
authorEli Zaretskii <eliz@gnu.org>
Fri, 12 Jul 2024 06:58:53 +0000 (09:58 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 13 Jul 2024 20:07:04 +0000 (22:07 +0200)
* lisp/shell.el (shell-eval-command): Fix detection of newline
after last output line.  (Bug#71896)
(shell-resync-dirs): Make sure the inner loop never infloops.
Suggested by Troy Hinckley <troyhinckley@dabrev.com>.

(cherry picked from commit 8b1a0f8695a43e74daa5275559267e96c14aba03)

lisp/shell.el

index 89ec893a3081ca55642d2a008f6cf4335d1dec56..835b300406fe9aca15f41fb02ae7c84246ab948c 100644 (file)
@@ -1254,7 +1254,7 @@ line output and parses it to form the new directory stack."
     (while dlsl
       (let ((newelt "")
             tem1 tem2)
-        (while newelt
+        (while (and dlsl newelt)
           ;; We need tem1 because we don't want to prepend
           ;; `comint-file-name-prefix' repeatedly into newelt via tem2.
           (setq tem1 (pop dlsl)
@@ -1628,10 +1628,14 @@ Returns t if successful."
           ;; a newline).  This is far from fool-proof -- if something
           ;; outputs incomplete data and then sleeps, we'll think
           ;; we've received the prompt.
-          (while (not (let* ((lines (string-lines result))
-                             (last (car (last lines))))
+          (while (not (let* ((lines (string-lines result nil t))
+                             (last (car (last lines)))
+                             (last-end (if (equal last "")
+                                           last
+                                         (substring last -1))))
                         (and (length> lines 0)
-                             (not (equal last ""))
+                             (not (member last '("" "\n")))
+                             (not (equal last-end "\n"))
                              (or (not prev)
                                  (not (equal last prev)))
                              (setq prev last))))