From afd1fdf6bb85600e6d7fafcdbff367c0f964a576 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 26 Jan 2022 14:13:00 +0100 Subject: [PATCH] Fix input of sharp-quoted symbols in Eshell with em-extpipe * lisp/eshell/em-extpipe.el (eshell-parse-external-pipeline): Fix misinterpreting sharp-quoted symbols as the beginning of single-quoted strings (Bug#53518). Add protection against a possible infinite loop. * test/lisp/eshell/em-extpipe-tests.el (em-extpipe-test-17): New test (bug#53518). --- lisp/eshell/em-extpipe.el | 13 ++++++++++--- test/lisp/eshell/em-extpipe-tests.el | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lisp/eshell/em-extpipe.el b/lisp/eshell/em-extpipe.el index 57aeec38ff6..eb5b3bfe1df 100644 --- a/lisp/eshell/em-extpipe.el +++ b/lisp/eshell/em-extpipe.el @@ -30,6 +30,7 @@ (require 'cl-lib) (require 'esh-arg) +(require 'esh-cmd) (require 'esh-io) (require 'esh-util) @@ -97,15 +98,21 @@ as though it were Eshell syntax." (while (> bound (point)) (let* ((found (save-excursion - (re-search-forward "['\"\\]" bound t))) + (re-search-forward + "\\(?:#?'\\|\"\\|\\\\\\)" bound t))) (next (or (and found (match-beginning 0)) bound))) (if (re-search-forward pat next t) (throw 'found (match-beginning 1)) (goto-char next) - (while (or (eshell-parse-backslash) + (while (or (eshell-parse-lisp-argument) + (eshell-parse-backslash) (eshell-parse-double-quote) - (eshell-parse-literal-quote))))))))) + (eshell-parse-literal-quote))) + ;; Guard against an infinite loop if none of + ;; the parsers moved us forward. + (unless (or (> (point) next) (eobp)) + (forward-char 1)))))))) (goto-char (if (and result go) (match-end 0) start)) result))) (unless (or eshell-current-argument eshell-current-quoted) diff --git a/test/lisp/eshell/em-extpipe-tests.el b/test/lisp/eshell/em-extpipe-tests.el index 1283b6b361f..0879ad5b0ca 100644 --- a/test/lisp/eshell/em-extpipe-tests.el +++ b/test/lisp/eshell/em-extpipe-tests.el @@ -202,4 +202,8 @@ (eshell-command-result-p input "rab") (eshell-command-result-p "echo \"bar\" | rev" "nonsense")))) +;; Confirm we don't break input of sharp-quoted symbols (Bug#53518). +(em-extpipe-tests--deftest em-extpipe-test-17 "funcall #'upcase foo" + (eshell-command-result-p input "FOO")) + ;;; em-extpipe-tests.el ends here -- 2.39.2