From a2d249d758f49ba528243204e32ecd0aa59c3105 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sun, 13 Jun 2021 02:15:55 -0700 Subject: [PATCH 2/2] 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 9fa1736535..8e2bb83360 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -2965,7 +2965,7 @@ erc-cmd-default 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 685f4e2bea..b2dbc1012d 100644 --- a/test/lisp/erc/erc-tests.el +++ b/test/lisp/erc/erc-tests.el @@ -236,6 +236,7 @@ erc-process-input-line (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 @@ erc-process-input-line ((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 @@ erc-process-input-line (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.31.1