From 1b1d387b96ebeb8330a76240db0cda6b8cefdf1f Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 13 Jun 2021 02:15:55 -0700 Subject: [PATCH] Don't send empty lines for unknown commands in ERC * lisp/erc/erc.el (erc-cmd-default): prevent excess trailing newlines from being sent. * test/lisp/erc/erc-tests.el: Update `erc-process-input-line' test to check for excess line feeds with unknown commands. --- lisp/erc/erc.el | 2 +- test/lisp/erc/erc-tests.el | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 9fa17365356..8e2bb833605 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2965,7 +2965,7 @@ Commands for which no erc-cmd-xxx exists, are tunneled through this function. LINE is sent to the server verbatim, and therefore has to contain the command itself as well." (erc-log (format "cmd: DEFAULT: %s" line)) - (erc-server-send (substring line 1)) + (erc-server-send (string-trim-right (substring line 1) "[\r\n]")) t) (defvar erc--read-time-period-history nil) diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el index 685f4e2bea2..b2dbc1012de 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -236,6 +236,7 @@ (let (erc-server-last-sent-time erc-server-flood-queue (orig-erc-cmd-MSG (symbol-function 'erc-cmd-MSG)) + (erc-default-recipients '("#chan")) calls) (with-temp-buffer (cl-letf (((symbol-function 'erc-cmd-MSG) @@ -247,9 +248,7 @@ ((symbol-function 'erc-server-process-alive) (lambda () t)) ((symbol-function 'erc-server-send-queue) - #'ignore) - ((symbol-function 'erc-default-target) - (lambda () "" "#chan"))) + #'ignore)) (ert-info ("Dispatch to user command handler") @@ -259,6 +258,16 @@ (should (equal (pop erc-server-flood-queue) '("PRIVMSG #chan :hi\r\n" . utf-8)))) + (ert-info ("Quote preserves line intact") + (erc-process-input-line "/QUOTE FAKE foo bar\n") + (should (equal (pop erc-server-flood-queue) + '("FAKE foo bar\r\n" . utf-8)))) + + (ert-info ("Unknown command respected") + (erc-process-input-line "/FAKE foo bar\n") + (should (equal (pop erc-server-flood-queue) + '("FAKE foo bar\r\n" . utf-8)))) + (ert-info ("Spaces preserved") (erc-process-input-line "/msg #chan hi you\n") (should (equal (pop calls) " #chan hi you")) -- 2.39.2