* 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).
(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))))))
(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