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:
parent
ade1424a97
commit
bb40507fed
@ -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))))))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user