mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-01-03 18:41:25 -08:00
Fix command-line parsing regression in erc-cmd-DCC
* lisp/erc/erc-compat.el (erc-compat--28-split-string-shell-command, erc-compat--split-string-shell-command): Remove unused function and macro. * lisp/erc/erc-dcc.el (erc-cmd-DCC): Use own arg-parsing function. * lisp/erc/erc.el (erc--shell-parse-regexp, erc--split-string-shell-cmd): New regexp constant and arg-parsing function based on those in shell.el. * test/lisp/erc/erc-dcc-tests.el (erc-dcc-tests--erc-dcc-do-GET-command): Accept new `nuh' argument representing message source/sender. (erc-dcc-do-GET-command): Add tests for regression involving pipe character. * test/lisp/erc/erc-tests.el (erc--split-string-shell-cmd): New test. (Bug#62444) Thanks to Fernando de Morais for reporting this bug.
This commit is contained in:
parent
4e8d579f3d
commit
b95bb644ec
5 changed files with 99 additions and 29 deletions
|
|
@ -445,27 +445,6 @@ If START or END is negative, it counts from the end."
|
|||
existing))))))
|
||||
|
||||
|
||||
;;;; Misc 28.1
|
||||
|
||||
(defvar comint-file-name-quote-list)
|
||||
(defvar shell-file-name-quote-list)
|
||||
(declare-function shell--parse-pcomplete-arguments "shell" nil)
|
||||
|
||||
(defun erc-compat--28-split-string-shell-command (string)
|
||||
(require 'comint)
|
||||
(require 'shell)
|
||||
(with-temp-buffer
|
||||
(insert string)
|
||||
(let ((comint-file-name-quote-list shell-file-name-quote-list))
|
||||
(car (shell--parse-pcomplete-arguments)))))
|
||||
|
||||
(defmacro erc-compat--split-string-shell-command (string)
|
||||
;; Autoloaded in Emacs 28.
|
||||
(list (if (fboundp 'split-string-shell-command)
|
||||
'split-string-shell-command
|
||||
'erc-compat--28-split-string-shell-command)
|
||||
string))
|
||||
|
||||
(provide 'erc-compat)
|
||||
|
||||
;;; erc-compat.el ends here
|
||||
|
|
|
|||
|
|
@ -399,7 +399,7 @@ where FOO is one of CLOSE, GET, SEND, LIST, CHAT, etc."
|
|||
(if compat-args
|
||||
(setq cmd line
|
||||
args compat-args)
|
||||
(setq args (delete "" (erc-compat--split-string-shell-command line))
|
||||
(setq args (delete "" (erc--split-string-shell-cmd line))
|
||||
cmd (pop args)))
|
||||
(let ((fn (intern-soft (concat "erc-dcc-do-" (upcase cmd) "-command"))))
|
||||
(if fn
|
||||
|
|
|
|||
|
|
@ -3213,6 +3213,42 @@ this function from interpreting the line as a command."
|
|||
(erc-display-message nil 'error (current-buffer) 'no-target)
|
||||
nil)))))
|
||||
|
||||
(defconst erc--shell-parse-regexp
|
||||
(rx (or (+ (not (any ?\s ?\t ?\n ?\\ ?\" ?' ?\;)))
|
||||
(: ?' (group (* (not ?'))) (? ?'))
|
||||
(: ?\" (group (* (or (not (any ?\" ?\\)) (: ?\\ nonl)))) (? ?\"))
|
||||
(: ?\\ (group (? (or nonl ?\n)))))))
|
||||
|
||||
(defun erc--split-string-shell-cmd (string)
|
||||
"Parse whitespace-separated arguments in STRING."
|
||||
;; From `shell--parse-pcomplete-arguments' and friends. Quirk:
|
||||
;; backslash-escaped characters appearing within spans of double
|
||||
;; quotes are unescaped.
|
||||
(with-temp-buffer
|
||||
(insert string)
|
||||
(let ((end (point))
|
||||
args)
|
||||
(goto-char (point-min))
|
||||
(while (and (skip-chars-forward " \t") (< (point) end))
|
||||
(let (arg)
|
||||
(while (looking-at erc--shell-parse-regexp)
|
||||
(goto-char (match-end 0))
|
||||
(cond ((match-beginning 3) ; backslash escape
|
||||
(push (if (= (match-beginning 3) (match-end 3))
|
||||
"\\"
|
||||
(match-string 3))
|
||||
arg))
|
||||
((match-beginning 2) ; double quote
|
||||
(push (replace-regexp-in-string (rx ?\\ (group nonl))
|
||||
"\\1" (match-string 2))
|
||||
arg))
|
||||
((match-beginning 1) ; single quote
|
||||
(push (match-string 1) arg))
|
||||
(t (push (match-string 0) arg))))
|
||||
(push (string-join (nreverse arg)) args)))
|
||||
(nreverse args))))
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Input commands handlers
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue