1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-29 19:48:19 +00:00

Handle escaped characters in Eshell argument predicates/modifiers

* lisp/eshell/em-pred.el (eshell-get-delimited-modifier-argument):
Unescape escaped characters.

* test/lisp/eshell/em-pred-tests.el (em-pred-test/predicate-escaping):
New test (bug#55204).
This commit is contained in:
Jim Porter 2022-04-26 21:51:23 -07:00 committed by Lars Ingebrigtsen
parent ade1424a97
commit bb40507fed
2 changed files with 15 additions and 1 deletions

View File

@ -416,7 +416,9 @@ before the closing delimiter. This allows modifiers like
(close (cdr (assoc open eshell-pred-delimiter-pairs)))
(end (eshell-find-delimiter open close nil nil t)))
(prog1
(buffer-substring-no-properties (1+ (point)) end)
(replace-regexp-in-string
(rx-to-string `(seq "\\" (group (or "\\" ,open ,close)))) "\\1"
(buffer-substring-no-properties (1+ (point)) end))
(goto-char (if (and chained-p (eq open close))
end
(1+ end))))))

View File

@ -533,4 +533,16 @@ PREDICATE is the predicate used to query that attribute."
(format ":j%c-%c" (car delims) (cdr delims)))
"foo-bar-baz"))))
(ert-deftest em-pred-test/predicate-escaping ()
"Test string escaping in predicate and modifier parameters."
;; Escaping the delimiter should remove the backslash.
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":j'\\''")
"foo'bar'baz"))
;; Escaping a backlash should remove the first backslash.
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":j'\\\\'")
"foo\\bar\\baz"))
;; Escaping a different character should keep the backslash.
(should (equal (eshell-eval-predicate '("foo" "bar" "baz") ":j'\\\"'")
"foo\\\"bar\\\"baz")))
;; em-pred-tests.el ends here