diff options
| author | F. Jason Park | 2023-07-07 21:27:03 -0700 |
|---|---|---|
| committer | F. Jason Park | 2023-07-13 18:45:31 -0700 |
| commit | b95bb644ec2b9bb9b0aa3ba2a88c828c3c33705a (patch) | |
| tree | cfb4f0215dfe9067f7cb1781af9b3a8e4c0781a5 /lisp/erc | |
| parent | 4e8d579f3da93f3f4cb5ae52c179623e75957ee4 (diff) | |
| download | emacs-b95bb644ec2b9bb9b0aa3ba2a88c828c3c33705a.tar.gz emacs-b95bb644ec2b9bb9b0aa3ba2a88c828c3c33705a.zip | |
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.
Diffstat (limited to 'lisp/erc')
| -rw-r--r-- | lisp/erc/erc-compat.el | 21 | ||||
| -rw-r--r-- | lisp/erc/erc-dcc.el | 2 | ||||
| -rw-r--r-- | lisp/erc/erc.el | 36 |
3 files changed, 37 insertions, 22 deletions
diff --git a/lisp/erc/erc-compat.el b/lisp/erc/erc-compat.el index 29892b78a39..f451aaee754 100644 --- a/lisp/erc/erc-compat.el +++ b/lisp/erc/erc-compat.el | |||
| @@ -445,27 +445,6 @@ If START or END is negative, it counts from the end." | |||
| 445 | existing)))))) | 445 | existing)))))) |
| 446 | 446 | ||
| 447 | 447 | ||
| 448 | ;;;; Misc 28.1 | ||
| 449 | |||
| 450 | (defvar comint-file-name-quote-list) | ||
| 451 | (defvar shell-file-name-quote-list) | ||
| 452 | (declare-function shell--parse-pcomplete-arguments "shell" nil) | ||
| 453 | |||
| 454 | (defun erc-compat--28-split-string-shell-command (string) | ||
| 455 | (require 'comint) | ||
| 456 | (require 'shell) | ||
| 457 | (with-temp-buffer | ||
| 458 | (insert string) | ||
| 459 | (let ((comint-file-name-quote-list shell-file-name-quote-list)) | ||
| 460 | (car (shell--parse-pcomplete-arguments))))) | ||
| 461 | |||
| 462 | (defmacro erc-compat--split-string-shell-command (string) | ||
| 463 | ;; Autoloaded in Emacs 28. | ||
| 464 | (list (if (fboundp 'split-string-shell-command) | ||
| 465 | 'split-string-shell-command | ||
| 466 | 'erc-compat--28-split-string-shell-command) | ||
| 467 | string)) | ||
| 468 | |||
| 469 | (provide 'erc-compat) | 448 | (provide 'erc-compat) |
| 470 | 449 | ||
| 471 | ;;; erc-compat.el ends here | 450 | ;;; erc-compat.el ends here |
diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el index cc2dcc9a788..f05ae41fc51 100644 --- a/lisp/erc/erc-dcc.el +++ b/lisp/erc/erc-dcc.el | |||
| @@ -399,7 +399,7 @@ where FOO is one of CLOSE, GET, SEND, LIST, CHAT, etc." | |||
| 399 | (if compat-args | 399 | (if compat-args |
| 400 | (setq cmd line | 400 | (setq cmd line |
| 401 | args compat-args) | 401 | args compat-args) |
| 402 | (setq args (delete "" (erc-compat--split-string-shell-command line)) | 402 | (setq args (delete "" (erc--split-string-shell-cmd line)) |
| 403 | cmd (pop args))) | 403 | cmd (pop args))) |
| 404 | (let ((fn (intern-soft (concat "erc-dcc-do-" (upcase cmd) "-command")))) | 404 | (let ((fn (intern-soft (concat "erc-dcc-do-" (upcase cmd) "-command")))) |
| 405 | (if fn | 405 | (if fn |
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index e23185934f7..1786c8924bd 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el | |||
| @@ -3213,6 +3213,42 @@ this function from interpreting the line as a command." | |||
| 3213 | (erc-display-message nil 'error (current-buffer) 'no-target) | 3213 | (erc-display-message nil 'error (current-buffer) 'no-target) |
| 3214 | nil))))) | 3214 | nil))))) |
| 3215 | 3215 | ||
| 3216 | (defconst erc--shell-parse-regexp | ||
| 3217 | (rx (or (+ (not (any ?\s ?\t ?\n ?\\ ?\" ?' ?\;))) | ||
| 3218 | (: ?' (group (* (not ?'))) (? ?')) | ||
| 3219 | (: ?\" (group (* (or (not (any ?\" ?\\)) (: ?\\ nonl)))) (? ?\")) | ||
| 3220 | (: ?\\ (group (? (or nonl ?\n))))))) | ||
| 3221 | |||
| 3222 | (defun erc--split-string-shell-cmd (string) | ||
| 3223 | "Parse whitespace-separated arguments in STRING." | ||
| 3224 | ;; From `shell--parse-pcomplete-arguments' and friends. Quirk: | ||
| 3225 | ;; backslash-escaped characters appearing within spans of double | ||
| 3226 | ;; quotes are unescaped. | ||
| 3227 | (with-temp-buffer | ||
| 3228 | (insert string) | ||
| 3229 | (let ((end (point)) | ||
| 3230 | args) | ||
| 3231 | (goto-char (point-min)) | ||
| 3232 | (while (and (skip-chars-forward " \t") (< (point) end)) | ||
| 3233 | (let (arg) | ||
| 3234 | (while (looking-at erc--shell-parse-regexp) | ||
| 3235 | (goto-char (match-end 0)) | ||
| 3236 | (cond ((match-beginning 3) ; backslash escape | ||
| 3237 | (push (if (= (match-beginning 3) (match-end 3)) | ||
| 3238 | "\\" | ||
| 3239 | (match-string 3)) | ||
| 3240 | arg)) | ||
| 3241 | ((match-beginning 2) ; double quote | ||
| 3242 | (push (replace-regexp-in-string (rx ?\\ (group nonl)) | ||
| 3243 | "\\1" (match-string 2)) | ||
| 3244 | arg)) | ||
| 3245 | ((match-beginning 1) ; single quote | ||
| 3246 | (push (match-string 1) arg)) | ||
| 3247 | (t (push (match-string 0) arg)))) | ||
| 3248 | (push (string-join (nreverse arg)) args))) | ||
| 3249 | (nreverse args)))) | ||
| 3250 | |||
| 3251 | |||
| 3216 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3252 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 3217 | ;; Input commands handlers | 3253 | ;; Input commands handlers |
| 3218 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 3254 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |