aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorF. Jason Park2021-11-06 03:09:43 +0100
committerLars Ingebrigtsen2021-11-06 03:09:43 +0100
commit4d656ea5ff7ba79315af42e159254867bfd157ad (patch)
tree03965e6c5cd08400222cbadbbe6741459d9514df
parent82d0550648969ce10303b67b7a8da51c4e855501 (diff)
downloademacs-4d656ea5ff7ba79315af42e159254867bfd157ad.tar.gz
emacs-4d656ea5ff7ba79315af42e159254867bfd157ad.zip
Don't send empty lines for implicit targets in ERC
* erc.el (erc-send-input-line): Previously, any line typed into a query or channel buffer without an explicit user-command handler (meaning most lines), would be sent twice because a trailing newline (linefeed) would be appended. This has been verified by checking IRCd server logs. IRCds won't return an error upon receiving an empty message, but they also won't forward them to channel subscribers and DM pals. * erc-tests.el: Add test for erc-process-input-line, which also indirectly tests erc-send-input-line. It also tests the command lookup and dispatch facility (bug#50008).
-rw-r--r--lisp/erc/erc.el21
-rw-r--r--test/lisp/erc/erc-tests.el62
2 files changed, 71 insertions, 12 deletions
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 88c105040c5..0da837012cc 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2817,20 +2817,17 @@ present."
2817 (let ((prop-val (erc-get-parsed-vector position))) 2817 (let ((prop-val (erc-get-parsed-vector position)))
2818 (and prop-val (member (erc-response.command prop-val) list)))) 2818 (and prop-val (member (erc-response.command prop-val) list))))
2819 2819
2820(defvar-local erc-send-input-line-function 'erc-send-input-line) 2820(defvar-local erc-send-input-line-function 'erc-send-input-line
2821 "Function for sending lines lacking a leading user command.
2822When a line typed into a buffer contains an explicit command, like /msg,
2823a corresponding handler (here, erc-cmd-MSG) is called. But lines typed
2824into a channel or query buffer already have an implicit target and
2825command (PRIVMSG). This function is called on such occasions and also
2826for special purposes (see erc-dcc.el).")
2821 2827
2822(defun erc-send-input-line (target line &optional force) 2828(defun erc-send-input-line (target line &optional force)
2823 "Send LINE to TARGET. 2829 "Send LINE to TARGET."
2824 2830 (erc-message "PRIVMSG" (concat target " " line) force))
2825See also `erc-server-send'."
2826 (setq line (format "PRIVMSG %s :%s"
2827 target
2828 ;; If the line is empty, we still want to
2829 ;; send it - i.e. an empty pasted line.
2830 (if (string= line "\n")
2831 " \n"
2832 line)))
2833 (erc-server-send line force target))
2834 2831
2835(defun erc-get-arglist (fun) 2832(defun erc-get-arglist (fun)
2836 "Return the argument list of a function without the parens." 2833 "Return the argument list of a function without the parens."
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 6ed26f68289..685f4e2bea2 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -228,4 +228,66 @@
228 (kill-buffer "*erc-protocol*") 228 (kill-buffer "*erc-protocol*")
229 (should-not erc-debug-irc-protocol))) 229 (should-not erc-debug-irc-protocol)))
230 230
231
232;; The point of this test is to ensure output is handled identically
233;; regardless of whether a command handler is summoned.
234
235(ert-deftest erc-process-input-line ()
236 (let (erc-server-last-sent-time
237 erc-server-flood-queue
238 (orig-erc-cmd-MSG (symbol-function 'erc-cmd-MSG))
239 calls)
240 (with-temp-buffer
241 (cl-letf (((symbol-function 'erc-cmd-MSG)
242 (lambda (line)
243 (push line calls)
244 (funcall orig-erc-cmd-MSG line)))
245 ((symbol-function 'erc-server-buffer)
246 (lambda () (current-buffer)))
247 ((symbol-function 'erc-server-process-alive)
248 (lambda () t))
249 ((symbol-function 'erc-server-send-queue)
250 #'ignore)
251 ((symbol-function 'erc-default-target)
252 (lambda () "" "#chan")))
253
254 (ert-info ("Dispatch to user command handler")
255
256 (ert-info ("Baseline")
257 (erc-process-input-line "/msg #chan hi\n")
258 (should (equal (pop calls) " #chan hi"))
259 (should (equal (pop erc-server-flood-queue)
260 '("PRIVMSG #chan :hi\r\n" . utf-8))))
261
262 (ert-info ("Spaces preserved")
263 (erc-process-input-line "/msg #chan hi you\n")
264 (should (equal (pop calls) " #chan hi you"))
265 (should (equal (pop erc-server-flood-queue)
266 '("PRIVMSG #chan :hi you\r\n" . utf-8))))
267
268 (ert-info ("Empty line honored")
269 (erc-process-input-line "/msg #chan\n")
270 (should (equal (pop calls) " #chan"))
271 (should (equal (pop erc-server-flood-queue)
272 '("PRIVMSG #chan :\r\n" . utf-8)))))
273
274 (ert-info ("Implicit cmd via `erc-send-input-line-function'")
275
276 (ert-info ("Baseline")
277 (erc-process-input-line "hi")
278 (should (equal (pop erc-server-flood-queue)
279 '("PRIVMSG #chan :hi\r\n" . utf-8))))
280
281 (ert-info ("Spaces preserved")
282 (erc-process-input-line "hi you")
283 (should (equal (pop erc-server-flood-queue)
284 '("PRIVMSG #chan :hi you\r\n" . utf-8))))
285
286 (ert-info ("Empty line transmitted without injected-space kludge")
287 (erc-process-input-line "")
288 (should (equal (pop erc-server-flood-queue)
289 '("PRIVMSG #chan :\r\n" . utf-8))))
290
291 (should-not calls))))))
292
231;;; erc-tests.el ends here 293;;; erc-tests.el ends here