Regression related to CTCP detection in erc-server-PRIVMSG

"J.P." <[email protected]>
Newsgroups gmane.emacs.erc.general
Message-ID <[email protected]>
A regression was introduced by

  * 1767b0bd7e Don't call erc-auto-query twice on PRIVMSG

Basically, a phantom query buffer appears when you accept a DCC CHAT
offer.

Someone on Libera recently mentioned an issue with DCC CHAT. If I can
track them down and the two issues seem related, I'll open a bug report.
Otherwise, I'll just add the following or similar relatively soon.
Thanks.
0001-Allow-non-IRC-line-delimiter-in-ERC-test-server.patch (text/x-patch, 6.1 KB)
From f36367ad0e57819a015fd6e9a3f28f3649fdba2a Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email protected]>
Date: Sun, 24 Jul 2022 05:14:24 -0700
Subject: [PATCH 1/3] Allow non-IRC line delimiter in ERC test server

* test/lisp/erc/resources/erc-d/erc-d.el (erc-d-server-fqdn,
erc-d--initialize-client, erc-d--log, erc-d--send, erc-d--filter,
erc-d-run): Add new variable and use it.

* test/lisp/erc/resources/erc-d/erc-d-tests.el
(erc-d-run-direct-foreign-protocol): Add test demoing newline-only
line-wise protocol.

* test/lisp/erc/resources/erc-d/resources/foreign.eld: New file.
---
 test/lisp/erc/resources/erc-d/erc-d-tests.el  | 27 +++++++++++++++++++
 test/lisp/erc/resources/erc-d/erc-d.el        | 16 ++++++++---
 .../erc/resources/erc-d/resources/foreign.eld |  5 ++++
 3 files changed, 44 insertions(+), 4 deletions(-)
 create mode 100644 test/lisp/erc/resources/erc-d/resources/foreign.eld

diff --git a/test/lisp/erc/resources/erc-d/erc-d-tests.el b/test/lisp/erc/resources/erc-d/erc-d-tests.el
index 21005cd760..019099edcc 100644
--- a/test/lisp/erc/resources/erc-d/erc-d-tests.el
+++ b/test/lisp/erc/resources/erc-d/erc-d-tests.el
@@ -1343,4 +1343,31 @@ erc-d-unix-socket-direct
             (kill-buffer dumb-server-buffer)))
       (delete-file sock))))
 
+(ert-deftest erc-d-run-direct-foreign-protocol ()
+  :tags '(:expensive-test)
+  (let* ((erc-d-line-ending "\n")
+         (server (erc-d-run "localhost" t "erc-d-server" 'foreign))
+         (server-buffer (get-buffer "*erc-d-server*"))
+         (client-buffer (get-buffer-create "*erc-d-client*"))
+         client)
+    (with-current-buffer server-buffer (erc-d-t-search-for 4 "Starting"))
+    (setq client (make-network-process
+                  :buffer client-buffer
+                  :name "erc-d-client"
+                  :family 'ipv4
+                  :noquery t
+                  :coding 'binary
+                  :service (process-contact server :service)
+                  :host "localhost"))
+    (process-send-string client "ONE one\n")
+    (with-current-buffer client-buffer
+      (erc-d-t-search-for 5 "echo ONE one"))
+    (process-send-string client "TWO two\n")
+    (with-current-buffer client-buffer
+      (erc-d-t-search-for 2 "echo TWO two"))
+    (erc-d-t-wait-for 2 "server death" (not (process-live-p server)))
+    (when noninteractive
+      (kill-buffer client-buffer)
+      (kill-buffer server-buffer))))
+
 ;;; erc-d-tests.el ends here
diff --git a/test/lisp/erc/resources/erc-d/erc-d.el b/test/lisp/erc/resources/erc-d/erc-d.el
index ee9b6a7fec..00cc704fc6 100644
--- a/test/lisp/erc/resources/erc-d/erc-d.el
+++ b/test/lisp/erc/resources/erc-d/erc-d.el
@@ -136,6 +136,9 @@ erc-d-server-fqdn
 Possibly used by overriding handlers, like the one for PING, and/or
 dialog templates for the sender portion of a reply message.")
 
+(defvar erc-d-line-ending "\r\n"
+  "Protocol line delimiter for sending and receiving.")
+
 (defvar erc-d-linger-secs nil
   "Seconds to wait before quitting for all dialogs.
 For more granular control, use the provided LINGER `rx' variable (alone)
@@ -249,6 +252,7 @@ erc-d--initialize-client
          (mat-h (copy-sequence (process-get process :dialog-match-handlers)))
          (fqdn (copy-sequence (process-get process :dialog-server-fqdn)))
          (vars (copy-sequence (process-get process :dialog-vars)))
+         (ending (process-get process :dialog-ending))
          (dialog (make-erc-d-dialog :name name
                                     :process process
                                     :queue (make-ring 5)
@@ -263,6 +267,8 @@ erc-d--initialize-client
           (erc-d-dialog-hunks dialog) reader)
     ;; Add reverse link, register client, launch
     (process-put process :dialog dialog)
+    (process-put process :ending ending)
+    (process-put process :ending-regexp (rx-to-string `(+ ,ending)))
     (push process erc-d--clients)
     (erc-d--command-refresh dialog nil)
     (erc-d--on-request process)))
@@ -311,7 +317,7 @@ erc-d--log
          (name (erc-d-dialog-name (process-get ,process :dialog))))
      (if ,outbound
          (erc-d--m process "-> %s:%s %s" name id ,string)
-       (dolist (line (split-string ,string "\r\n"))
+       (dolist (line (split-string ,string (process-get process :ending)))
          (erc-d--m process "<- %s:%s %s" name id line)))))
 
 (defun erc-d--log-process-event (server process msg)
@@ -320,7 +326,7 @@ erc-d--log-process-event
 (defun erc-d--send (process string)
   "Send STRING to PROCESS peer."
   (erc-d--log process string 'outbound)
-  (process-send-string process (concat string "\r\n")))
+  (process-send-string process (concat string (process-get process :ending))))
 
 (define-inline erc-d--fuzzy-p (exchange)
   (inline-letevals (exchange)
@@ -442,9 +448,10 @@ erc-d--filter
   "Handle input received from peer.
 PROCESS represents a client peer connection and STRING is a raw request
 including line delimiters."
-  (let ((queue (erc-d-dialog-queue (process-get process :dialog))))
+  (let ((queue (erc-d-dialog-queue (process-get process :dialog)))
+        (delim (process-get process :ending-regexp)))
     (setq string (concat (process-get process :stashed-input) string))
-    (while (and string (string-match (rx (+ "\r\n")) string))
+    (while (and string (string-match delim string))
       (let ((line (substring string 0 (match-beginning 0))))
         (setq string (unless (= (match-end 0) (length string))
                        (substring string (match-end 0))))
@@ -940,6 +947,7 @@ erc-d-run
                 :dialog-vars erc-d-tmpl-vars
                 :dialog-linger-secs erc-d-linger-secs
                 :dialog-server-fqdn erc-d-server-fqdn
+                :dialog-ending erc-d-line-ending
                 :dialog-match-handlers (erc-d-u--unkeyword
                                         erc-d-match-handlers)))
 
diff --git a/test/lisp/erc/resources/erc-d/resources/foreign.eld b/test/lisp/erc/resources/erc-d/resources/foreign.eld
new file mode 100644
index 0000000000..64a5dca8b1
--- /dev/null
+++ b/test/lisp/erc/resources/erc-d/resources/foreign.eld
@@ -0,0 +1,5 @@
+;;; -*- mode: lisp-data -*-
+((one 5 "ONE one")
+ (0 "echo ONE one"))
+((two 5 "TWO two")
+ (0 "echo TWO two"))
-- 
2.36.1
0002-Fix-CTCP-regression-in-erc-server-PRIVMSG.patch (text/x-patch, 7 KB)
From 2afa7fe45aa29a3d27bcfed96b6c24c6000ff9cd Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email protected]>
Date: Sun, 24 Jul 2022 05:14:24 -0700
Subject: [PATCH 2/3] Fix CTCP regression in erc-server-PRIVMSG

* lisp/erc/erc-backend.el (erc-server-PRIVMSG): Don't create a query
buffer for non-ACTION CTCP messages.

* test/lisp/erc/erc-scenarios-misc.el (erc-scenarios-dcc-chat-accept):
Add test for basic DCC CHAT accept dialog.

* test/lisp/erc/resources/dcc/chat/accept-dcc.eld: New file.
* test/lisp/erc/resources/dcc/chat/accept.eld: New file.
---
 lisp/erc/erc-backend.el                       |  5 ++-
 lisp/erc/erc.el                               |  5 ++-
 test/lisp/erc/erc-scenarios-misc.el           | 40 +++++++++++++++++++
 .../erc/resources/dcc/chat/accept-dcc.eld     |  3 ++
 test/lisp/erc/resources/dcc/chat/accept.eld   | 23 +++++++++++
 5 files changed, 72 insertions(+), 4 deletions(-)
 create mode 100644 test/lisp/erc/resources/dcc/chat/accept-dcc.eld
 create mode 100644 test/lisp/erc/resources/dcc/chat/accept.eld

diff --git a/lisp/erc/erc-backend.el b/lisp/erc/erc-backend.el
index 8be4894ecb..f7981dff27 100644
--- a/lisp/erc/erc-backend.el
+++ b/lisp/erc/erc-backend.el
@@ -1526,8 +1526,9 @@ define-erc-response-handler
         (setf (erc-response.contents parsed) msg)
         (setq buffer (erc-get-buffer (if privp nick tgt) proc))
         ;; Even worth checking for empty target here? (invalid anyway)
-        (unless (or buffer noticep (string-empty-p tgt) (eq ?$ (aref tgt 0)))
-          (if (and privp msgp (not (erc-is-message-ctcp-and-not-action-p msg)))
+        (unless (or buffer noticep (string-empty-p tgt) (eq ?$ (aref tgt 0))
+                    (erc-is-message-ctcp-and-not-action-p msg))
+          (if privp
               (when erc-auto-query
                 (let ((erc-join-buffer erc-auto-query))
                   (setq buffer (erc--open-target nick))))
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 4b852b3904..3b127bbd49 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -4654,8 +4654,9 @@ erc-auto-query
                  (const :tag "Use current buffer" buffer)
                  (const :tag "Use current buffer" t)))
 
-;; FIXME either retire this or put it to use or more clearly explain
-;; what it's supposed to do.  It's currently only used by the obsolete
+;; FIXME either retire this or put it to use after determining how
+;; it's meant to work.  Clearly, the doc string does not describe
+;; current behavior.  It's currently only used by the obsolete
 ;; function `erc-auto-query'.
 (defcustom erc-query-on-unjoined-chan-privmsg t
   "If non-nil create query buffer on receiving any PRIVMSG at all.
diff --git a/test/lisp/erc/erc-scenarios-misc.el b/test/lisp/erc/erc-scenarios-misc.el
index 9d6d5bc1d6..d107689558 100644
--- a/test/lisp/erc/erc-scenarios-misc.el
+++ b/test/lisp/erc/erc-scenarios-misc.el
@@ -138,4 +138,44 @@ erc-scenarios-base-mask-target-routing
 
     (should-not (get-buffer "$*"))))
 
+(ert-deftest erc-scenarios-dcc-chat-accept ()
+  :tags '(:expensive-test)
+  (erc-scenarios-common-with-cleanup
+      ((erc-scenarios-common-dialog "dcc/chat")
+       (erc-d-line-ending "\n")
+       (dcc-server (erc-d-run "127.0.0.1" t "erc-dcc-server" 'accept-dcc))
+       (dcc-port (process-contact dcc-server :service))
+       (erc-d-tmpl-vars `((port . ,(number-to-string dcc-port))))
+       (erc-d-line-ending "\r\n")
+       (dumb-server (erc-d-run "localhost" t 'accept))
+       (port (process-contact dumb-server :service))
+       (expect (erc-d-t-make-expecter)))
+
+    (ert-info ("Connect to foonet")
+      (with-current-buffer (erc :server "127.0.0.1"
+                                :port port
+                                :nick "tester"
+                                :password "changeme"
+                                :full-name "tester")
+        (should (string= (buffer-name) (format "127.0.0.1:%d" port)))))
+
+    (ert-info ("Offer received")
+      (with-current-buffer (erc-d-t-wait-for 10 (get-buffer "foonet"))
+        (funcall expect 10 "DCC: chat offered by dummy")
+        (erc-cmd-DCC "CHAT" "dummy")))
+
+    ;; Regression
+    (erc-d-t-ensure-for 1 (not (get-buffer "tester")))
+
+    ;; Becomes current buffer by default (because `erc-join-buffer')
+    (erc-d-t-wait-for 10 (get-buffer "DCC-CHAT-dummy"))
+
+    (with-current-buffer "foonet"
+      (funcall expect 10 "*** DCC: accepting chat from dummy"))
+
+    (ert-info ("Chat with dummy")
+      (with-current-buffer "DCC-CHAT-dummy"
+        (erc-scenarios-common-say "Hi")
+        (funcall expect 10 "Hola")))))
+
 ;;; erc-scenarios-misc.el ends here
diff --git a/test/lisp/erc/resources/dcc/chat/accept-dcc.eld b/test/lisp/erc/resources/dcc/chat/accept-dcc.eld
new file mode 100644
index 0000000000..23828a8115
--- /dev/null
+++ b/test/lisp/erc/resources/dcc/chat/accept-dcc.eld
@@ -0,0 +1,3 @@
+;; -*- mode: lisp-data; -*-
+((open 10 "Hi")
+ (0 "Hola"))
diff --git a/test/lisp/erc/resources/dcc/chat/accept.eld b/test/lisp/erc/resources/dcc/chat/accept.eld
new file mode 100644
index 0000000000..a23e9580bc
--- /dev/null
+++ b/test/lisp/erc/resources/dcc/chat/accept.eld
@@ -0,0 +1,23 @@
+;; -*- mode: lisp-data; -*-
+((pass 1 "PASS :changeme"))
+((nick 1 "NICK tester"))
+((user 1 "USER user 0 * :tester")
+ (0 ":irc.foonet.org 001 tester :Welcome to the foonet IRC Network tester")
+ (0 ":irc.foonet.org 002 tester :Your host is irc.foonet.org, running version oragono-2.6.0-7481bf0385b95b16")
+ (0 ":irc.foonet.org 003 tester :This server was created Mon, 31 May 2021 09:56:24 UTC")
+ (0 ":irc.foonet.org 004 tester irc.foonet.org oragono-2.6.0-7481bf0385b95b16 BERTZios CEIMRUabefhiklmnoqstuv Iabefhkloqv")
+ (0 ":irc.foonet.org 005 tester AWAYLEN=390 BOT=B CASEMAPPING=ascii CHANLIMIT=#:100 CHANMODES=Ibe,k,fl,CEMRUimnstu CHANNELLEN=64 CHANTYPES=# ELIST=U EXCEPTS EXTBAN=,m FORWARD=f INVEX KICKLEN=390 :are supported by this server")
+ (0 ":irc.foonet.org 005 tester MAXLIST=beI:60 MAXTARGETS=4 MODES MONITOR=100 NETWORK=foonet NICKLEN=32 PREFIX=(qaohv)~&@%+ STATUSMSG=~&@%+ TARGMAX=NAMES:1,LIST:1,KICK:1,WHOIS:1,USERHOST:10,PRIVMSG:4,TAGMSG:4,NOTICE:4,MONITOR:100 TOPICLEN=390 UTF8MAPPING=rfc8265 UTF8ONLY WHOX :are supported by this server")
+ (0 ":irc.foonet.org 005 tester draft/CHATHISTORY=100 :are supported by this server")
+ (0 ":irc.foonet.org 251 tester :There are 0 users and 4 invisible on 1 server(s)")
+ (0 ":irc.foonet.org 252 tester 0 :IRC Operators online")
+ (0 ":irc.foonet.org 254 tester 2 :channels formed")
+ (0 ":irc.foonet.org 255 tester :I have 4 clients and 0 servers")
+ (0 ":irc.foonet.org 265 tester 4 4 :Current local users 4, max 4")
+ (0 ":irc.foonet.org 266 tester 4 4 :Current global users 4, max 4")
+ (0 ":irc.foonet.org 422 tester :MOTD File is missing"))
+
+((mode-user 1.2 "MODE tester +i")
+ ;; No mode answer
+ (0 ":irc.foonet.org NOTICE tester :This server is in debug mode and is logging all user I/O. If you do not wish for everything you send to be readable by the server owner(s), please disconnect.")
+ (0.2 ":[email protected] PRIVMSG tester :\C-aDCC CHAT chat 2130706433 " port "\C-a"))
-- 
2.36.1
0003-Ensure-erc-dcc-chat-setup-runs-in-intended-buffer.patch (text/x-patch, 1.9 KB)
From 02b6d66c88ef1dba4d8f1028bbb0a500b854477c Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <[email protected]>
Date: Sun, 24 Jul 2022 05:14:24 -0700
Subject: [PATCH 3/3] Ensure erc-dcc-chat-setup runs in intended buffer

* lisp/erc/erc-dcc.el (erc-dcc-chat-setup): Ensure initialization runs
in the intended buffer regardless of the value of `erc-join-buffer'.
---
 lisp/erc/erc-dcc.el | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/lisp/erc/erc-dcc.el b/lisp/erc/erc-dcc.el
index d0e1848e0e..993d452774 100644
--- a/lisp/erc/erc-dcc.el
+++ b/lisp/erc/erc-dcc.el
@@ -1182,18 +1182,18 @@ erc-dcc-chat-setup
          (proc (plist-get entry :peer))
          (parent-proc (plist-get entry :parent)))
     (erc-setup-buffer buffer)
-    ;; buffer is now the current buffer.
-    (erc-dcc-chat-mode)
-    (setq erc-server-process parent-proc)
-    (setq erc-dcc-from nick)
-    (setq erc-dcc-entry-data entry)
-    (setq erc-dcc-unprocessed-output "")
-    (setq erc-insert-marker (point-max-marker))
-    (setq erc-input-marker (make-marker))
-    (erc-display-prompt buffer (point-max))
-    (set-process-buffer proc buffer)
-    (add-hook 'kill-buffer-hook #'erc-dcc-chat-buffer-killed nil t)
-    (run-hook-with-args 'erc-dcc-chat-connect-hook proc)
+    (with-current-buffer buffer
+      (erc-dcc-chat-mode)
+      (setq erc-server-process parent-proc
+            erc-dcc-from nick
+            erc-dcc-entry-data entry
+            erc-dcc-unprocessed-output ""
+            erc-insert-marker (point-max-marker)
+            erc-input-marker (make-marker))
+      (erc-display-prompt buffer (point-max))
+      (set-process-buffer proc buffer)
+      (add-hook 'kill-buffer-hook #'erc-dcc-chat-buffer-killed nil t)
+      (run-hook-with-args 'erc-dcc-chat-connect-hook proc))
     buffer))
 
 (defun erc-dcc-chat-accept (entry parent-proc)
-- 
2.36.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.