all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args
@ 2022-12-30 14:15 J.P.
  0 siblings, 0 replies; 2+ messages in thread
From: J.P. @ 2022-12-30 14:15 UTC (permalink / raw)
  To: 60428; +Cc: emacs-erc

[-- Attachment #1: Type: text/plain, Size: 4934 bytes --]

Tags: patch

To reproduce from emacs -Q, do an M-x erc and accept the default offered
at every prompt. Assuming your IP is not blacklisted by Libera, you
should see a connection failure immediately because a TLS endpoint is
dialed but negotiation never occurs.

This all stems from a lapse in professionalism on my part: an
underrealized feature snuck in with the changes from bug#56514, but
missing logic made it impossible to connect using the default prompt
values, which should probably always succeed because some people don't
care about parameters and just want to get there somehow (so I'm told).
Alternatively, if a deliberate failure is indeed warranted (an arguably
valid position), the error message should at least explain as much.

FWIW, the missing feature was supposed to offer an interactive upgrade
to TLS upon detecting a user's intent to connect to the default server
and, on confirmation, adjust ERC's parameters on the fly. The proposed
patch abandons most of the envisioned niceties and instead employs a
hack to just force a non-local exit and schedule a call to `erc-tls'
when appropriate. It also instructs users to do that themselves in the
future (issue an M-x erc-tls, that is). Hopefully, this makes for an
acceptable compromise.

BTW, a POC patch set far more faithful to the original breadth of the
feature (and way less hacky) is also attached. Perhaps it'll inform
further exploration in this area down the road (but not for Emacs 29).

Thanks.

P.S. Shout out to the Libera users who brought this to my attention.


In GNU Emacs 29.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.35, cairo version 1.17.6) of 2022-12-29 built on localhost
Repository revision: d086cd6cf877c6ca7af6712f9b79b52dd0caa934
Repository branch: emacs-29
Windowing system distributor 'The X.Org Foundation', version 11.0.12014000
System Description: Fedora Linux 36 (Workstation Edition)

Configured using:
 'configure --enable-check-lisp-object-type --enable-checking=yes,glyphs
 'CFLAGS=-O0 -g3'
 PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ JPEG
JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NOTIFY
INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: @im=ibus
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec epa epg rfc6068 epg-config gnus-util
text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils erc rx derived pcase url-parse url-vars
iso8601 time-date auth-source cl-seq eieio eieio-core cl-macs
password-cache json subr-x map thingatpt pp format-spec cl-loaddefs
cl-lib erc-backend erc-goodies erc-networks byte-opt gv bytecomp
byte-compile erc-common erc-compat erc-loaddefs rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
emacs)

Memory information:
((conses 16 91094 5621)
 (symbols 48 9313 0)
 (strings 32 24582 1551)
 (string-bytes 1 743674)
 (vectors 16 14587)
 (vector-slots 8 205402 10021)
 (floats 8 24 35)
 (intervals 56 234 0)
 (buffers 976 10))


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-default-port-regression-in-erc-select-read-args.patch --]
[-- Type: text/x-patch, Size: 5409 bytes --]

From 78fe57488bb69f8f48e31fcd1ffcc31f31253207 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 1/4] Fix default-port regression in erc-select-read-args

* lisp/erc/erc.el (erc-select-read-args): Fix incomplete feature
introduced by bug#56514.  Ensure connecting always possible with
non-TLS default port, but offer upgrade.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect a prompt
and possible `user-error' when calling `erc' interactively with all
default arguments.
---
 lisp/erc/erc.el            | 38 +++++++++++++++++++++++++++++---------
 test/lisp/erc/erc-tests.el | 13 +++++++++----
 2 files changed, 38 insertions(+), 13 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 16a0aba77b..98d55bb1ae 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2171,10 +2171,7 @@ erc-select-read-args
          ;; For legacy reasons, also accept a URL without a scheme.
          (url (url-generic-parse-url (erc--ensure-url input)))
          (server (url-host url))
-         (sp (and (or (string-suffix-p "s" (url-type url))
-                      (and (equal server erc-default-server)
-                           (not (string-prefix-p "irc://" input))))
-                  'ircs-u))
+         (sp (and (string-suffix-p "s" (url-type url)) erc-default-port-tls))
          (port (or (url-portspec url)
                    (erc-compute-port
                     (let ((d (erc-compute-port sp))) ; may be a string
@@ -2188,12 +2185,35 @@ erc-select-read-args
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
          (passwd (or (url-password url)
-                     (if erc-prompt-for-password
-                         (read-passwd "Server password (optional): ")
-                       (with-suppressed-warnings ((obsolete erc-password))
-                         erc-password)))))
+                     (let*
+                         ((p (with-suppressed-warnings
+                                 ((obsolete erc-password))
+                               erc-password))
+                          (m (if p
+                                 (format "Server password (default is %S): " p)
+                               "Server password (optional): ")))
+                       (if erc-prompt-for-password (read-passwd m nil p) p)))))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
+    (when-let (((equal server erc-default-server))
+               ((eql port erc-default-port))
+               ((not (string-prefix-p "irc://" input))) ; ignore irc6://
+               (key (substitute-command-keys "\\[erc-tls]"))
+               ((y-or-n-p (concat
+                           "Switch to " key " now instead of connecting "
+                           (propertize "unencrypted" 'face 'error) "?"))))
+      (run-at-time nil nil
+                   (lambda ()
+                     (with-suppressed-warnings ((obsolete erc-password))
+                       (let ((erc-nick nick)
+                             (erc-password passwd))
+                         (with-temp-message (format "Switching to %s ..." key)
+                           (sit-for 1))
+                         (with-current-buffer (call-interactively #'erc-tls)
+                           (erc-display-error-notice
+                            nil (format "Please use %s directly from now on."
+                                        key)))))))
+      (user-error "Non-TLS connection to default server detected"))
     (list :server server :port port :nick nick :password passwd)))
 
 ;;;###autoload
@@ -2287,7 +2307,7 @@ erc-tls
 See info node `(erc) Network Identifier' for details.  Like USER
 and CLIENT-CERTIFICATE, this parameter cannot be specified
 interactively."
-  (interactive (let ((erc-default-port erc-default-port-tls))
+  (interactive (let ((erc-port (or erc-port erc-default-port-tls)))
 		 (erc-select-read-args)))
   (let ((erc-server-connect-function 'erc-open-tls-stream))
     (erc-open server port nick full-name t password
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 578b2641a6..400b92d29e 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,15 +1001,20 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Defaults to TLS")
-    (should (equal (ert-simulate-keys "\r\r\r\r"
+  (ert-info ("Error signaled with default server and non-TLS port")
+    (should (pcase (should-error (ert-simulate-keys "\r\r\r\ry\r"
+                                   (erc-select-read-args)))
+              (`(user-error ,(rx "Non-TLS")) 'passed))))
+
+  (ert-info ("Opt out of non-TLS warning manually")
+    (should (equal (ert-simulate-keys "\r\r\r\rn\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
-                         :port 6697
+                         :port 6667
                          :nick (user-login-name)
                          :password nil))))
 
-  (ert-info ("Override default TLS")
+  (ert-info ("Override non-TLS warning via URL scheme")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-POC-Offer-TLS-by-default-for-M-x-erc.patch --]
[-- Type: text/x-patch, Size: 10134 bytes --]

From c2108baadd06a2301e379d41fcb5bbe9f03c2baf Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 2/4] [POC] Offer TLS by default for M-x erc

* lisp/erc/erc.el (erc-select-read-args): Offer to use TLS when user
runs M-x erc and opts for default server and port.  But do this
immediately instead of calling `erc-tls' interactively and imposing a
review of just-chosen values.  Also remove error warnings and ensure
`erc-tls' still works by setting `erc-server-connect-function' to
`erc-open-tls-stream' when appropriate.
(erc, erc-tls): Add internal keyword arguments for interactive use,
but don't make them colon-prefixed, i.e., `keywordp'.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Modify return
values to expect additional `connect-function' keyword argument.
---
 lisp/erc/erc.el            | 59 +++++++++++++++++++++-----------------
 test/lisp/erc/erc-tests.el | 42 +++++++++++++--------------
 2 files changed, 52 insertions(+), 49 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 98d55bb1ae..86149f7d2f 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2192,29 +2192,19 @@ erc-select-read-args
                           (m (if p
                                  (format "Server password (default is %S): " p)
                                "Server password (optional): ")))
-                       (if erc-prompt-for-password (read-passwd m nil p) p)))))
+                       (if erc-prompt-for-password (read-passwd m nil p) p))))
+         (opener erc-server-connect-function))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
-    (when-let (((equal server erc-default-server))
-               ((eql port erc-default-port))
-               ((not (string-prefix-p "irc://" input))) ; ignore irc6://
-               (key (substitute-command-keys "\\[erc-tls]"))
-               ((y-or-n-p (concat
-                           "Switch to " key " now instead of connecting "
-                           (propertize "unencrypted" 'face 'error) "?"))))
-      (run-at-time nil nil
-                   (lambda ()
-                     (with-suppressed-warnings ((obsolete erc-password))
-                       (let ((erc-nick nick)
-                             (erc-password passwd))
-                         (with-temp-message (format "Switching to %s ..." key)
-                           (sit-for 1))
-                         (with-current-buffer (call-interactively #'erc-tls)
-                           (erc-display-error-notice
-                            nil (format "Please use %s directly from now on."
-                                        key)))))))
-      (user-error "Non-TLS connection to default server detected"))
-    (list :server server :port port :nick nick :password passwd)))
+    (when (and (equal server erc-default-server)
+               (not (string-prefix-p "irc://" input))
+               (or (not (eql port erc-default-port))
+                   (and (y-or-n-p "Connect using TLS instead? ")
+                        (setq port erc-default-port-tls))))
+      (setq opener #'erc-open-tls-stream))
+    `( :server ,server :port ,port :nick ,nick
+       ,@(and passwd `(:password ,passwd)) connect-function ,opener)))
+
 
 ;;;###autoload
 (cl-defun erc (&key (server (erc-compute-server))
@@ -2223,7 +2213,10 @@ erc
                     (user   (erc-compute-user))
                     password
                     (full-name (erc-compute-full-name))
-                    id)
+                    id
+                    ;; For interactive use
+                    ((connect-function erc-server-connect-function)
+                     erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC.
 
@@ -2246,7 +2239,9 @@ erc
 whereas `erc-compute-port' and `erc-compute-nick' will be invoked
 for the values of the other parameters.
 
-See `erc-tls' for the meaning of ID."
+See `erc-tls' for the meaning of ID.
+
+\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME ID)"
   (interactive (erc-select-read-args))
   (erc-open server port nick full-name t password nil nil nil nil user id))
 
@@ -2262,7 +2257,10 @@ erc-tls
                         password
                         (full-name (erc-compute-full-name))
                         client-certificate
-                        id)
+                        id
+                        ;; For interactive use
+                        ((connect-function erc-server-connect-function)
+                         #'erc-open-tls-stream))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC over TLS.
 
@@ -2306,10 +2304,17 @@ erc-tls
 the server buffer and identifying the connection unequivocally.
 See info node `(erc) Network Identifier' for details.  Like USER
 and CLIENT-CERTIFICATE, this parameter cannot be specified
-interactively."
-  (interactive (let ((erc-port (or erc-port erc-default-port-tls)))
+interactively.
+
+\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
+  (interactive (let ((erc-server-connect-function
+                      (if (eq erc-server-connect-function
+                              #'erc-open-network-stream)
+                          #'erc-open-tls-stream
+                        erc-server-connect-function))
+                     (erc-port (or erc-port erc-default-port-tls)))
 		 (erc-select-read-args)))
-  (let ((erc-server-connect-function 'erc-open-tls-stream))
+  (progn
     (erc-open server port nick full-name t password
               nil nil nil client-certificate user id)))
 
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 400b92d29e..fb23aa3c0a 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,10 +1001,13 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Error signaled with default server and non-TLS port")
-    (should (pcase (should-error (ert-simulate-keys "\r\r\r\ry\r"
-                                   (erc-select-read-args)))
-              (`(user-error ,(rx "Non-TLS")) 'passed))))
+  (ert-info ("Doesn't default to TLS")
+    (should (equal (ert-simulate-keys "\r\r\r\ry\r"
+                     (erc-select-read-args))
+                   (list :server "irc.libera.chat"
+                         :port 6697
+                         :nick (user-login-name)
+                         'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Opt out of non-TLS warning manually")
     (should (equal (ert-simulate-keys "\r\r\r\rn\r"
@@ -1012,7 +1015,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Override non-TLS warning via URL scheme")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
@@ -1020,29 +1023,27 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes port")
-    (should (equal (ert-simulate-keys
-                       "localhost:6667\rnick\r\r"
+    (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r"
                      (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
-                         :password nil))))
+                         'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes nick, password skipped via option")
     (should (equal (ert-simulate-keys "nick@localhost:6667\r"
                      (let (erc-prompt-for-password)
-                       (erc-select-read-args)))
+                       (butlast (erc-select-read-args) 2)))
                    (list :server "localhost"
                          :port 6667
-                         :nick "nick"
-                         :password nil))))
+                         :nick "nick"))))
 
   (ert-info ("Address includes nick and password")
     (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
@@ -1050,27 +1051,24 @@ erc-select-read-args
 
   (ert-info ("IPv6 address plain")
     (should (equal (ert-simulate-keys "::1\r\r\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address with port")
     (should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address includes nick")
     (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
-                     (erc-select-read-args))
+                     (butlast (erc-select-read-args) 2))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick"
-                         :password nil)))))
+                         :nick "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-POC-Display-buffers-differently-for-M-x-erc.patch --]
[-- Type: text/x-patch, Size: 6805 bytes --]

From 6dd5bf870aec52b44080676301849c6d5059985a Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 3/4] [POC] Display buffers differently for M-x erc

* lisp/erc/erc.el (erc-buffer-display): Add alias for
`erc-join-buffer'.
(erc-interactive-display): Add new option to control display of server
buffers during interactive entry-point invocations.
(erc-select-read-args): Pass `erc-interactive-display' to entry
points.
(erc, erc-tls): Add interactive-only to control initial buffer
display.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect
buffer-display values from `erc-interactive-display'.
---
 lisp/erc/erc.el            | 20 +++++++++++++++++++-
 test/lisp/erc/erc-tests.el | 14 +++++++++-----
 2 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 86149f7d2f..049e8af350 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1459,6 +1459,7 @@ erc-default-port-tls
   "IRC port to use for encrypted connections if it cannot be \
 detected otherwise.")
 
+(defvaralias 'erc-buffer-display 'erc-join-buffer)
 (defcustom erc-join-buffer 'bury
   "Determines how to display a newly created IRC buffer.
 
@@ -1479,6 +1480,18 @@ erc-join-buffer
                  (const :tag "Use current buffer" buffer)
                  (const :tag "Use current buffer" t)))
 
+(defcustom erc-interactive-display 'buffer
+  "How and whether to display server buffers for M-x erc.
+See `erc-buffer-display' and friends for a description of
+possible values."
+  :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
+  :group 'erc-buffers
+  :type '(choice (const :tag "Split window and select" window)
+                 (const :tag "Split window, don't select" window-noselect)
+                 (const :tag "New frame" frame)
+                 (const :tag "Bury new and don't display existing" bury)
+                 (const :tag "Use current buffer" buffer)))
+
 (defcustom erc-reconnect-display nil
   "How (and whether) to display a channel buffer upon reconnecting.
 
@@ -2203,7 +2216,8 @@ erc-select-read-args
                         (setq port erc-default-port-tls))))
       (setq opener #'erc-open-tls-stream))
     `( :server ,server :port ,port :nick ,nick
-       ,@(and passwd `(:password ,passwd)) connect-function ,opener)))
+       ,@(and passwd `(:password ,passwd))
+       buffer-display ,erc-interactive-display connect-function ,opener)))
 
 
 ;;;###autoload
@@ -2215,6 +2229,8 @@ erc
                     (full-name (erc-compute-full-name))
                     id
                     ;; For interactive use
+                    ((buffer-display erc-buffer-display)
+                     erc-buffer-display)
                     ((connect-function erc-server-connect-function)
                      erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
@@ -2259,6 +2275,8 @@ erc-tls
                         client-certificate
                         id
                         ;; For interactive use
+                        ((buffer-display erc-buffer-display)
+                         erc-buffer-display)
                         ((connect-function erc-server-connect-function)
                          #'erc-open-tls-stream))
   "ERC is a powerful, modular, and extensible IRC client.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index fb23aa3c0a..6d60c9e274 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1007,6 +1007,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6697
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Opt out of non-TLS warning manually")
@@ -1015,6 +1016,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Override non-TLS warning via URL scheme")
@@ -1023,6 +1025,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6667
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes port")
@@ -1031,19 +1034,20 @@ erc-select-read-args
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-network-stream))))
 
   (ert-info ("Address includes nick, password skipped via option")
     (should (equal (ert-simulate-keys "nick@localhost:6667\r"
                      (let (erc-prompt-for-password)
-                       (butlast (erc-select-read-args) 2)))
+                       (butlast (erc-select-read-args) 4)))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"))))
 
   (ert-info ("Address includes nick and password")
     (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r"
-                     (butlast (erc-select-read-args) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
@@ -1051,21 +1055,21 @@ erc-select-read-args
 
   (ert-info ("IPv6 address plain")
     (should (equal (ert-simulate-keys "::1\r\r\r\r"
-                     (butlast (erc-select-read-args) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
                          :nick (user-login-name)))))
 
   (ert-info ("IPv6 address with port")
     (should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
-                     (butlast (erc-select-read-args) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
                          :nick (user-login-name)))))
 
   (ert-info ("IPv6 address includes nick")
     (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
-                     (butlast (erc-select-read-args) 2))
+                     (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
                          :nick "nick")))))
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-POC-Optionally-prompt-for-more-ERC-entry-point-param.patch --]
[-- Type: text/x-patch, Size: 4767 bytes --]

From 66575cffd38d576f93348b089ec77e1b6e1dad57 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 4/4] [POC] Optionally prompt for more ERC entry-point params

* doc/misc/erc.texi: Update statement about availability of user param
when entry points called interactively.
* lisp/erc/erc.el (erc-select-read-args): Allow optionally calling
entry points with a prefix arg to access params `user' and
`:full-name'.
(erc-tls): Update doc string.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Add test for
extra args.
---
 doc/misc/erc.texi          |  2 +-
 lisp/erc/erc.el            | 19 ++++++++++++++-----
 test/lisp/erc/erc-tests.el | 13 ++++++++++++-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi
index 249b58c73d..2e3b635f5e 100644
--- a/doc/misc/erc.texi
+++ b/doc/misc/erc.texi
@@ -932,7 +932,7 @@ SASL
 your @samp{NickServ} password.  To make this work, customize
 @code{erc-sasl-user} and @code{erc-sasl-password} or specify the
 @code{:user} and @code{:password} keyword arguments when invoking
-@code{erc-tls}.  Note that @code{:user} cannot be given interactively.
+@code{erc-tls}.
 
 @item @code{external} (via Client TLS Certificate)
 This works in conjunction with the @code{:client-certificate} keyword
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 049e8af350..585fba079f 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2176,7 +2176,8 @@ erc--ensure-url
 
 ;;;###autoload
 (defun erc-select-read-args ()
-  "Prompt the user for values of nick, server, port, and password."
+  "Prompt the user for values of nick, server, port, and password.
+With prefix arg, also prompt for user and full name."
   (require 'url-parse)
   (let* ((input (let ((d (erc-compute-server)))
                   (read-string (format "Server (default is %S): " d)
@@ -2197,6 +2198,14 @@ erc-select-read-args
                    (let ((d (erc-compute-nick)))
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
+         (user (and current-prefix-arg
+                    (let ((d (or (url-user url) (erc-compute-user))))
+                      (read-string (format "User (default is %S): " d)
+                                   nil nil d))))
+         (full (and current-prefix-arg
+                    (let ((d (or (url-user url) (erc-compute-full-name))))
+                      (read-string (format "Full name (default is %S): " d)
+                                   nil nil d))))
          (passwd (or (url-password url)
                      (let*
                          ((p (with-suppressed-warnings
@@ -2215,8 +2224,8 @@ erc-select-read-args
                    (and (y-or-n-p "Connect using TLS instead? ")
                         (setq port erc-default-port-tls))))
       (setq opener #'erc-open-tls-stream))
-    `( :server ,server :port ,port :nick ,nick
-       ,@(and passwd `(:password ,passwd))
+    `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user))
+       ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full))
        buffer-display ,erc-interactive-display connect-function ,opener)))
 
 
@@ -2320,8 +2329,8 @@ erc-tls
 
 When present, ID should be a symbol or a string to use for naming
 the server buffer and identifying the connection unequivocally.
-See info node `(erc) Network Identifier' for details.  Like USER
-and CLIENT-CERTIFICATE, this parameter cannot be specified
+See info node `(erc) Network Identifier' for details.  Like
+CLIENT-CERTIFICATE, this parameter cannot be specified
 interactively.
 
 \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 6d60c9e274..e3df32d773 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1072,7 +1072,18 @@ erc-select-read-args
                      (butlast (erc-select-read-args) 4))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick")))))
+                         :nick "nick"))))
+
+  (ert-info ("Extra args use URL nick by default")
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r"
+                     (let ((current-prefix-arg '(4)))
+                       (butlast (erc-select-read-args) 4)))
+                   (list :server "localhost"
+                         :port 6667
+                         :nick "nick"
+                         :user "nick"
+                         :password "sesame"
+                         :full-name "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args
       [not found] <87mt750ygt.fsf@neverwas.me>
@ 2023-01-02  1:41 ` J.P.
  0 siblings, 0 replies; 2+ messages in thread
From: J.P. @ 2023-01-02  1:41 UTC (permalink / raw)
  To: 60428; +Cc: emacs-erc

[-- Attachment #1: Type: text/plain, Size: 976 bytes --]

v2. Respect `erc-prompt-for-password'. Remove `run-at-time' hack from
regression fix.

"J.P." <jp@neverwas.me> writes:

> The proposed patch abandons most of the envisioned niceties and
> instead employs a hack to just force a non-local exit and schedule a
> call to `erc-tls' when appropriate. It also instructs users to do that
> themselves in the future (issue an M-x erc-tls, that is). Hopefully,
> this makes for an acceptable compromise.

I've forsaken the first part out of an abundance of caution. So this now
just prints a warning and proceeds with a non-TLS connection. If anyone
finds that unsatisfactory, please say something.

> BTW, a POC patch set far more faithful to the original breadth of the
> feature (and way less hacky) is also attached. Perhaps it'll inform
> further exploration in this area down the road (but not for Emacs 29).

IOW, the de facto goal here is to make interactive `erc' a "universal"
entry point for both plain and TLS connections.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0000-v1-v2.diff --]
[-- Type: text/x-patch, Size: 12273 bytes --]

From 448686bf96105833cd3e3ee319118c1672d95ca0 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Sun, 1 Jan 2023 17:36:36 -0800
Subject: [PATCH 0/4] *** NOT A PATCH ***

*** BLURB HERE ***

F. Jason Park (4):
  Fix default-port regression in erc-select-read-args
  [5.6] Be smarter about switching to TLS from M-x erc
  [5.6] Add display option for interactive ERC invocations
  [5.6] Optionally prompt for more ERC entry-point params

 doc/misc/erc.texi          |  2 +-
 lisp/erc/erc.el            | 87 +++++++++++++++++++++++++++++---------
 test/lisp/erc/erc-tests.el | 66 +++++++++++++++++++++--------
 3 files changed, 118 insertions(+), 37 deletions(-)

Interdiff:
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 2fcdb513b5d..7f2dd89342b 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1486,7 +1486,8 @@ erc-interactive-display
 possible values."
   :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
   :group 'erc-buffers
-  :type '(choice (const :tag "Split window and select" window)
+  :type '(choice (const :tag "Use value of `erc-join-buffer'" nil)
+                 (const :tag "Split window and select" window)
                  (const :tag "Split window, don't select" window-noselect)
                  (const :tag "New frame" frame)
                  (const :tag "Bury new and don't display existing" bury)
@@ -2180,7 +2181,7 @@ erc-select-read-args
 With prefix arg, also prompt for user and full name."
   (require 'url-parse)
   (let* ((input (let ((d (erc-compute-server)))
-                  (read-string (format "Server (default is %S): " d)
+                  (read-string (format "Server or URL (default is %S): " d)
                                nil 'erc-server-history-list d)))
          ;; For legacy reasons, also accept a URL without a scheme.
          (url (url-generic-parse-url (erc--ensure-url input)))
@@ -2199,34 +2200,33 @@ erc-select-read-args
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
          (user (and current-prefix-arg
-                    (let ((d (or (url-user url) (erc-compute-user))))
+                    (let ((d (erc-compute-user (url-user url))))
                       (read-string (format "User (default is %S): " d)
                                    nil nil d))))
          (full (and current-prefix-arg
-                    (let ((d (or (url-user url) (erc-compute-full-name))))
+                    (let ((d (erc-compute-full-name (url-user url))))
                       (read-string (format "Full name (default is %S): " d)
                                    nil nil d))))
-         (passwd (or (url-password url)
-                     (let*
-                         ((p (with-suppressed-warnings
-                                 ((obsolete erc-password))
-                               erc-password))
-                          (m (if p
-                                 (format "Server password (default is %S): " p)
-                               "Server password (optional): ")))
-                       (if erc-prompt-for-password (read-passwd m nil p) p))))
-         (opener erc-server-connect-function))
+         (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password))
+                             (or (url-password url) erc-password)))
+                        (m (if p
+                               (format "Server password (default is %S): " p)
+                             "Server password (optional): ")))
+                   (if erc-prompt-for-password (read-passwd m nil p) p)))
+         (opener (and (or sp (eql port erc-default-port-tls)
+                          (and (equal server erc-default-server)
+                               (not (string-prefix-p "irc://" input))
+                               (eql port erc-default-port)
+                               (y-or-n-p "Connect using TLS instead? ")
+                               (setq port erc-default-port-tls)))
+                      #'erc-open-tls-stream)))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
-    (when (and (equal server erc-default-server)
-               (not (string-prefix-p "irc://" input))
-               (or (not (eql port erc-default-port))
-                   (and (y-or-n-p "Connect using TLS instead? ")
-                        (setq port erc-default-port-tls))))
-      (setq opener #'erc-open-tls-stream))
     `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user))
        ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full))
-       buffer-display ,erc-interactive-display connect-function ,opener)))
+       ,@(and erc-interactive-display
+              `(buffer-display ,erc-interactive-display))
+       ,@(and opener `(connect-function ,opener)))))
 
 
 ;;;###autoload
@@ -2238,8 +2238,7 @@ erc
                     (full-name (erc-compute-full-name))
                     id
                     ;; For interactive use
-                    ((buffer-display erc-buffer-display)
-                     erc-buffer-display)
+                    ((buffer-display erc-join-buffer) erc-join-buffer)
                     ((connect-function erc-server-connect-function)
                      erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
@@ -2284,10 +2283,12 @@ erc-tls
                         client-certificate
                         id
                         ;; For interactive use
-                        ((buffer-display erc-buffer-display)
-                         erc-buffer-display)
+                        ((buffer-display erc-join-buffer) erc-join-buffer)
                         ((connect-function erc-server-connect-function)
-                         #'erc-open-tls-stream))
+                         (if (eq erc-server-connect-function
+                                 #'erc-open-network-stream)
+                             #'erc-open-tls-stream
+                           erc-server-connect-function)))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC over TLS.
 
@@ -2334,12 +2335,7 @@ erc-tls
 interactively.
 
 \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
-  (interactive (let ((erc-server-connect-function
-                      (if (eq erc-server-connect-function
-                              #'erc-open-network-stream)
-                          #'erc-open-tls-stream
-                        erc-server-connect-function))
-                     (erc-port (or erc-port erc-default-port-tls)))
+  (interactive (let ((erc-default-port erc-default-port-tls))
 		 (erc-select-read-args)))
   (progn
     (erc-open server port nick full-name t password
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 9d09df44883..d05b0efe2ed 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,7 +1001,7 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Doesn't default to TLS")
+  (ert-info ("Prompts for switch to TLS by default")
     (should (equal (ert-simulate-keys "\r\r\r\ry\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
@@ -1010,44 +1010,58 @@ erc-select-read-args
                          'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
+  (ert-info ("Switches to TLS when port matches default TLS port")
+    (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r"
+                     (erc-select-read-args))
+                   (list :server "irc.gnu.org"
+                         :port 6697
+                         :nick (user-login-name)
+                         'buffer-display 'buffer
+                         'connect-function #'erc-open-tls-stream))))
+
+  (ert-info ("Switches to TLS when URL is ircs://")
+    (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r"
+                     (erc-select-read-args))
+                   (list :server "irc.gnu.org"
+                         :port 6697
+                         :nick (user-login-name)
+                         'buffer-display 'buffer
+                         'connect-function #'erc-open-tls-stream))))
+
+  (setq-local erc-interactive-display nil) ; cheat to save space
+
   (ert-info ("Opt out of non-TLS warning manually")
     (should (equal (ert-simulate-keys "\r\r\r\rn\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
                          :port 6667
-                         :nick (user-login-name)
-                         'buffer-display 'buffer
-                         'connect-function #'erc-open-network-stream))))
+                         :nick (user-login-name)))))
 
-  (ert-info ("Override non-TLS warning via URL scheme")
+  (ert-info ("Override default TLS")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
                          :port 6667
-                         :nick (user-login-name)
-                         'buffer-display 'buffer
-                         'connect-function #'erc-open-network-stream))))
+                         :nick (user-login-name)))))
 
   (ert-info ("Address includes port")
     (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r"
                      (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
-                         :nick "nick"
-                         'buffer-display 'buffer
-                         'connect-function #'erc-open-network-stream))))
+                         :nick "nick"))))
 
   (ert-info ("Address includes nick, password skipped via option")
     (should (equal (ert-simulate-keys "nick@localhost:6667\r"
                      (let (erc-prompt-for-password)
-                       (butlast (erc-select-read-args) 4)))
+                       (erc-select-read-args)))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"))))
 
   (ert-info ("Address includes nick and password")
-    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r"
-                     (butlast (erc-select-read-args) 4))
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r"
+                     (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
@@ -1055,29 +1069,29 @@ erc-select-read-args
 
   (ert-info ("IPv6 address plain")
     (should (equal (ert-simulate-keys "::1\r\r\r\r"
-                     (butlast (erc-select-read-args) 4))
+                     (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
                          :nick (user-login-name)))))
 
   (ert-info ("IPv6 address with port")
     (should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
-                     (butlast (erc-select-read-args) 4))
+                     (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
                          :nick (user-login-name)))))
 
   (ert-info ("IPv6 address includes nick")
     (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
-                     (butlast (erc-select-read-args) 4))
+                     (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
                          :nick "nick"))))
 
   (ert-info ("Extra args use URL nick by default")
-    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r"
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r"
                      (let ((current-prefix-arg '(4)))
-                       (butlast (erc-select-read-args) 4)))
+                       (erc-select-read-args)))
                    (list :server "localhost"
                          :port 6667
                          :nick "nick"
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Fix-default-port-regression-in-erc-select-read-args.patch --]
[-- Type: text/x-patch, Size: 5458 bytes --]

From 574671c8bdc1cb5a56b0c4ffe0f35be9fa0161f7 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 1/4] Fix default-port regression in erc-select-read-args

* lisp/erc/erc.el (erc--warn-unencrypted): New function, likely
temporary, to warn new users connecting interactively to the default
server, "irc.libara.chat", via the default non-TLS port, 6667.
(erc-select-read-args): Remove stray code from incomplete feature
introduced by bug#56514.  Ensure connecting always works with default
port, which is non-TLS.  Respect `erc-prompt-for-password' when user
pastes URL containing password component into "server" prompt.  Maybe
add `erc--warn-unencrypted' as one-off hook for impending connection.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Always expect
password prompt and sometimes a non-TLS port when `erc' called
interactively.  (Bug#60428.)
---
 lisp/erc/erc.el            | 38 +++++++++++++++++++++++++++++---------
 test/lisp/erc/erc-tests.el |  6 +++---
 2 files changed, 32 insertions(+), 12 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index fe1201dd3a8..6315d5aa482 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2161,6 +2161,23 @@ erc--ensure-url
     (setq input (concat "irc://" input)))
   input)
 
+;; A temporary means of addressing the problem of ERC's namesake entry
+;; point defaulting to a non-TLS connection with its default server
+;; (bug#60428).
+(defun erc--warn-unencrypted ()
+  ;; Remove unconditionally to avoid wrong context due to races from
+  ;; simultaneous dialing or aborting (e.g., via `keybaord-quit').
+  (remove-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted)
+  (when (and (process-contact erc-server-process :nowait)
+             (equal erc-session-server erc-default-server)
+             (eql erc-session-port erc-default-port))
+    ;; FIXME use the autoloaded `info' instead of `Info-goto-node' in
+    ;; `erc-button-alist'.
+    (require 'info nil t)
+    (erc-display-error-notice
+     nil (concat "This connection is unencrypted.  Please use `erc-tls'"
+                 " from now on.  See Info:\"(erc) connecting\" for more."))))
+
 ;;;###autoload
 (defun erc-select-read-args ()
   "Prompt the user for values of nick, server, port, and password."
@@ -2171,10 +2188,7 @@ erc-select-read-args
          ;; For legacy reasons, also accept a URL without a scheme.
          (url (url-generic-parse-url (erc--ensure-url input)))
          (server (url-host url))
-         (sp (and (or (string-suffix-p "s" (url-type url))
-                      (and (equal server erc-default-server)
-                           (not (string-prefix-p "irc://" input))))
-                  'ircs-u))
+         (sp (and (string-suffix-p "s" (url-type url)) erc-default-port-tls))
          (port (or (url-portspec url)
                    (erc-compute-port
                     (let ((d (erc-compute-port sp))) ; may be a string
@@ -2187,13 +2201,19 @@ erc-select-read-args
                    (let ((d (erc-compute-nick)))
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
-         (passwd (or (url-password url)
-                     (if erc-prompt-for-password
-                         (read-passwd "Server password (optional): ")
-                       (with-suppressed-warnings ((obsolete erc-password))
-                         erc-password)))))
+         (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password))
+                             (or (url-password url) erc-password)))
+                        (m (if p
+                               (format "Server password (default is %S): " p)
+                             "Server password (optional): ")))
+                   (if erc-prompt-for-password (read-passwd m nil p) p))))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
+    (when (and (equal server erc-default-server)
+               (eql port erc-default-port)
+               (not (eql port erc-default-port-tls)) ; not `erc-tls'
+               (not (string-prefix-p "irc://" input))) ; not yanked URL
+      (add-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted))
     (list :server server :port port :nick nick :password passwd)))
 
 ;;;###autoload
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 6807b24bfc6..85506c3d27e 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,11 +1001,11 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Defaults to TLS")
+  (ert-info ("Does not default to TLS")
     (should (equal (ert-simulate-keys "\r\r\r\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
-                         :port 6697
+                         :port 6667
                          :nick (user-login-name)
                          :password nil))))
 
@@ -1036,7 +1036,7 @@ erc-select-read-args
                          :password nil))))
 
   (ert-info ("Address includes nick and password")
-    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r"
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r"
                      (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0002-5.6-Be-smarter-about-switching-to-TLS-from-M-x-erc.patch --]
[-- Type: text/x-patch, Size: 10968 bytes --]

From 7a8659ed2132858e5c52cf09c9050cc00463607f Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 2/4] [5.6] Be smarter about switching to TLS from M-x erc

* lisp/erc/erc.el (erc--warn-unencrypted): Remove newly unused
internal function.
(erc-select-read-args): Offer to use TLS when user runs M-x erc and
opts for default server and port or provides the well-known IANA TLS
port or enters an ircs:// URL at the server prompt.  For the last two,
do this immediately instead of calling `erc-tls' interactively and
imposing a review of just-chosen values.  Also remove error warnings
and ensure `erc-tls' still works by setting
`erc-server-connect-function' to `erc-open-tls-stream' when
appropriate.  Include the word "URL" in server prompt.
(erc, erc-tls): Add internal keyword arguments for interactive use,
but don't make them colon-prefixed, i.e., `keywordp'.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Modify return
values to expect additional `connect-function' keyword argument.
(Bug#60428.)
---
 lisp/erc/erc.el            | 61 +++++++++++++++++++-------------------
 test/lisp/erc/erc-tests.el | 52 +++++++++++++++++++++-----------
 2 files changed, 65 insertions(+), 48 deletions(-)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 6315d5aa482..96866432ebd 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2161,29 +2161,12 @@ erc--ensure-url
     (setq input (concat "irc://" input)))
   input)
 
-;; A temporary means of addressing the problem of ERC's namesake entry
-;; point defaulting to a non-TLS connection with its default server
-;; (bug#60428).
-(defun erc--warn-unencrypted ()
-  ;; Remove unconditionally to avoid wrong context due to races from
-  ;; simultaneous dialing or aborting (e.g., via `keybaord-quit').
-  (remove-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted)
-  (when (and (process-contact erc-server-process :nowait)
-             (equal erc-session-server erc-default-server)
-             (eql erc-session-port erc-default-port))
-    ;; FIXME use the autoloaded `info' instead of `Info-goto-node' in
-    ;; `erc-button-alist'.
-    (require 'info nil t)
-    (erc-display-error-notice
-     nil (concat "This connection is unencrypted.  Please use `erc-tls'"
-                 " from now on.  See Info:\"(erc) connecting\" for more."))))
-
 ;;;###autoload
 (defun erc-select-read-args ()
   "Prompt the user for values of nick, server, port, and password."
   (require 'url-parse)
   (let* ((input (let ((d (erc-compute-server)))
-                  (read-string (format "Server (default is %S): " d)
+                  (read-string (format "Server or URL (default is %S): " d)
                                nil 'erc-server-history-list d)))
          ;; For legacy reasons, also accept a URL without a scheme.
          (url (url-generic-parse-url (erc--ensure-url input)))
@@ -2206,15 +2189,20 @@ erc-select-read-args
                         (m (if p
                                (format "Server password (default is %S): " p)
                              "Server password (optional): ")))
-                   (if erc-prompt-for-password (read-passwd m nil p) p))))
+                   (if erc-prompt-for-password (read-passwd m nil p) p)))
+         (opener (and (or sp (eql port erc-default-port-tls)
+                          (and (equal server erc-default-server)
+                               (not (string-prefix-p "irc://" input))
+                               (eql port erc-default-port)
+                               (y-or-n-p "Connect using TLS instead? ")
+                               (setq port erc-default-port-tls)))
+                      #'erc-open-tls-stream)))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
-    (when (and (equal server erc-default-server)
-               (eql port erc-default-port)
-               (not (eql port erc-default-port-tls)) ; not `erc-tls'
-               (not (string-prefix-p "irc://" input))) ; not yanked URL
-      (add-hook 'erc--server-post-connect-hook #'erc--warn-unencrypted))
-    (list :server server :port port :nick nick :password passwd)))
+    `( :server ,server :port ,port :nick ,nick
+       ,@(and passwd `(:password ,passwd))
+       ,@(and opener `(connect-function ,opener)))))
+
 
 ;;;###autoload
 (cl-defun erc (&key (server (erc-compute-server))
@@ -2223,7 +2211,10 @@ erc
                     (user   (erc-compute-user))
                     password
                     (full-name (erc-compute-full-name))
-                    id)
+                    id
+                    ;; For interactive use
+                    ((connect-function erc-server-connect-function)
+                     erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC.
 
@@ -2246,7 +2237,9 @@ erc
 whereas `erc-compute-port' and `erc-compute-nick' will be invoked
 for the values of the other parameters.
 
-See `erc-tls' for the meaning of ID."
+See `erc-tls' for the meaning of ID.
+
+\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME ID)"
   (interactive (erc-select-read-args))
   (erc-open server port nick full-name t password nil nil nil nil user id))
 
@@ -2262,7 +2255,13 @@ erc-tls
                         password
                         (full-name (erc-compute-full-name))
                         client-certificate
-                        id)
+                        id
+                        ;; For interactive use
+                        ((connect-function erc-server-connect-function)
+                         (if (eq erc-server-connect-function
+                                 #'erc-open-network-stream)
+                             #'erc-open-tls-stream
+                           erc-server-connect-function)))
   "ERC is a powerful, modular, and extensible IRC client.
 This function is the main entry point for ERC over TLS.
 
@@ -2306,10 +2305,12 @@ erc-tls
 the server buffer and identifying the connection unequivocally.
 See info node `(erc) Network Identifier' for details.  Like USER
 and CLIENT-CERTIFICATE, this parameter cannot be specified
-interactively."
+interactively.
+
+\(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
   (interactive (let ((erc-default-port erc-default-port-tls))
 		 (erc-select-read-args)))
-  (let ((erc-server-connect-function 'erc-open-tls-stream))
+  (progn
     (erc-open server port nick full-name t password
               nil nil nil client-certificate user id)))
 
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 85506c3d27e..10adc9d53a7 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1001,30 +1001,50 @@ erc--server-connect-dumb-ipv6-regexp
 
 (ert-deftest erc-select-read-args ()
 
-  (ert-info ("Does not default to TLS")
-    (should (equal (ert-simulate-keys "\r\r\r\r"
+  (ert-info ("Prompts for switch to TLS by default")
+    (should (equal (ert-simulate-keys "\r\r\r\ry\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
-                         :port 6667
+                         :port 6697
                          :nick (user-login-name)
-                         :password nil))))
+                         'connect-function #'erc-open-tls-stream))))
+
+  (ert-info ("Switches to TLS when port matches default TLS port")
+    (should (equal (ert-simulate-keys "irc.gnu.org\r6697\r\r\r"
+                     (erc-select-read-args))
+                   (list :server "irc.gnu.org"
+                         :port 6697
+                         :nick (user-login-name)
+                         'connect-function #'erc-open-tls-stream))))
+
+  (ert-info ("Switches to TLS when URL is ircs://")
+    (should (equal (ert-simulate-keys "ircs://irc.gnu.org\r\r\r\r"
+                     (erc-select-read-args))
+                   (list :server "irc.gnu.org"
+                         :port 6697
+                         :nick (user-login-name)
+                         'connect-function #'erc-open-tls-stream))))
+
+  (ert-info ("Opt out of non-TLS warning manually")
+    (should (equal (ert-simulate-keys "\r\r\r\rn\r"
+                     (erc-select-read-args))
+                   (list :server "irc.libera.chat"
+                         :port 6667
+                         :nick (user-login-name)))))
 
   (ert-info ("Override default TLS")
     (should (equal (ert-simulate-keys "irc://irc.libera.chat\r\r\r\r"
                      (erc-select-read-args))
                    (list :server "irc.libera.chat"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("Address includes port")
-    (should (equal (ert-simulate-keys
-                       "localhost:6667\rnick\r\r"
+    (should (equal (ert-simulate-keys "localhost:6667\rnick\r\r"
                      (erc-select-read-args))
                    (list :server "localhost"
                          :port 6667
-                         :nick "nick"
-                         :password nil))))
+                         :nick "nick"))))
 
   (ert-info ("Address includes nick, password skipped via option")
     (should (equal (ert-simulate-keys "nick@localhost:6667\r"
@@ -1032,8 +1052,7 @@ erc-select-read-args
                        (erc-select-read-args)))
                    (list :server "localhost"
                          :port 6667
-                         :nick "nick"
-                         :password nil))))
+                         :nick "nick"))))
 
   (ert-info ("Address includes nick and password")
     (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r"
@@ -1048,24 +1067,21 @@ erc-select-read-args
                      (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address with port")
     (should (equal (ert-simulate-keys "[::1]:6667\r\r\r"
                      (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
-                         :nick (user-login-name)
-                         :password nil))))
+                         :nick (user-login-name)))))
 
   (ert-info ("IPv6 address includes nick")
     (should (equal (ert-simulate-keys "nick@[::1]:6667\r\r"
                      (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick"
-                         :password nil)))))
+                         :nick "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0003-5.6-Add-display-option-for-interactive-ERC-invocatio.patch --]
[-- Type: text/x-patch, Size: 5138 bytes --]

From 5afc6f4d40af031258bcda8fe440448ce8a1aa01 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 3/4] [5.6] Add display option for interactive ERC invocations

* lisp/erc/erc.el (erc-buffer-display, erc-receive-query-display):
Add aliases for `erc-join-buffer' and `erc-auto-query'.
(erc-interactive-display): Add new option to control display of server
buffers during interactive entry-point invocations.
(erc-select-read-args): Pass `erc-interactive-display' to entry
points.
(erc, erc-tls): Add interactive-only to control initial buffer
display.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Expect
buffer-display values from `erc-interactive-display'.  (Bug#60428.)
---
 lisp/erc/erc.el            | 19 +++++++++++++++++++
 test/lisp/erc/erc-tests.el |  5 +++++
 2 files changed, 24 insertions(+)

diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 96866432ebd..09d55f60990 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -1459,6 +1459,7 @@ erc-default-port-tls
   "IRC port to use for encrypted connections if it cannot be \
 detected otherwise.")
 
+(defvaralias 'erc-buffer-display 'erc-join-buffer)
 (defcustom erc-join-buffer 'bury
   "Determines how to display a newly created IRC buffer.
 
@@ -1479,6 +1480,19 @@ erc-join-buffer
                  (const :tag "Use current buffer" buffer)
                  (const :tag "Use current buffer" t)))
 
+(defcustom erc-interactive-display 'buffer
+  "How and whether to display server buffers for M-x erc.
+See `erc-buffer-display' and friends for a description of
+possible values."
+  :package-version '(ERC . "5.4.1") ; FIXME increment upon publishing to ELPA
+  :group 'erc-buffers
+  :type '(choice (const :tag "Use value of `erc-join-buffer'" nil)
+                 (const :tag "Split window and select" window)
+                 (const :tag "Split window, don't select" window-noselect)
+                 (const :tag "New frame" frame)
+                 (const :tag "Bury new and don't display existing" bury)
+                 (const :tag "Use current buffer" buffer)))
+
 (defcustom erc-reconnect-display nil
   "How (and whether) to display a channel buffer upon reconnecting.
 
@@ -2201,6 +2215,8 @@ erc-select-read-args
       (setq passwd nil))
     `( :server ,server :port ,port :nick ,nick
        ,@(and passwd `(:password ,passwd))
+       ,@(and erc-interactive-display
+              `(buffer-display ,erc-interactive-display))
        ,@(and opener `(connect-function ,opener)))))
 
 
@@ -2213,6 +2229,7 @@ erc
                     (full-name (erc-compute-full-name))
                     id
                     ;; For interactive use
+                    ((buffer-display erc-join-buffer) erc-join-buffer)
                     ((connect-function erc-server-connect-function)
                      erc-server-connect-function))
   "ERC is a powerful, modular, and extensible IRC client.
@@ -2257,6 +2274,7 @@ erc-tls
                         client-certificate
                         id
                         ;; For interactive use
+                        ((buffer-display erc-join-buffer) erc-join-buffer)
                         ((connect-function erc-server-connect-function)
                          (if (eq erc-server-connect-function
                                  #'erc-open-network-stream)
@@ -4492,6 +4510,7 @@ erc-query
   (with-current-buffer server-buffer
     (erc--open-target target)))
 
+(defvaralias 'erc-receive-query-display 'erc-auto-query)
 (defcustom erc-auto-query 'window-noselect
   "If non-nil, create a query buffer each time you receive a private message.
 If the buffer doesn't already exist, it is created.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 10adc9d53a7..91cdf2f1770 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1007,6 +1007,7 @@ erc-select-read-args
                    (list :server "irc.libera.chat"
                          :port 6697
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Switches to TLS when port matches default TLS port")
@@ -1015,6 +1016,7 @@ erc-select-read-args
                    (list :server "irc.gnu.org"
                          :port 6697
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
   (ert-info ("Switches to TLS when URL is ircs://")
@@ -1023,8 +1025,11 @@ erc-select-read-args
                    (list :server "irc.gnu.org"
                          :port 6697
                          :nick (user-login-name)
+                         'buffer-display 'buffer
                          'connect-function #'erc-open-tls-stream))))
 
+  (setq-local erc-interactive-display nil) ; cheat to save space
+
   (ert-info ("Opt out of non-TLS warning manually")
     (should (equal (ert-simulate-keys "\r\r\r\rn\r"
                      (erc-select-read-args))
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0004-5.6-Optionally-prompt-for-more-ERC-entry-point-param.patch --]
[-- Type: text/x-patch, Size: 4839 bytes --]

From 448686bf96105833cd3e3ee319118c1672d95ca0 Mon Sep 17 00:00:00 2001
From: "F. Jason Park" <jp@neverwas.me>
Date: Thu, 29 Dec 2022 06:43:19 -0800
Subject: [PATCH 4/4] [5.6] Optionally prompt for more ERC entry-point params

* doc/misc/erc.texi: Update statement about availability of user param
when entry points called interactively.
* lisp/erc/erc.el (erc-select-read-args): Allow optionally calling
entry points with a prefix arg to access params `user' and
`:full-name'.
(erc-tls): Update doc string.
* test/lisp/erc/erc-tests.el (erc-select-read-args): Add test for
extra args.  (Bug#60428.)
---
 doc/misc/erc.texi          |  2 +-
 lisp/erc/erc.el            | 19 ++++++++++++++-----
 test/lisp/erc/erc-tests.el | 13 ++++++++++++-
 3 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/doc/misc/erc.texi b/doc/misc/erc.texi
index 23cdcbff575..40ecd00b226 100644
--- a/doc/misc/erc.texi
+++ b/doc/misc/erc.texi
@@ -932,7 +932,7 @@ SASL
 your @samp{NickServ} password.  To make this work, customize
 @code{erc-sasl-user} and @code{erc-sasl-password} or specify the
 @code{:user} and @code{:password} keyword arguments when invoking
-@code{erc-tls}.  Note that @code{:user} cannot be given interactively.
+@code{erc-tls}.
 
 @item @code{external} (via Client TLS Certificate)
 This works in conjunction with the @code{:client-certificate} keyword
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 09d55f60990..7f2dd89342b 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -2177,7 +2177,8 @@ erc--ensure-url
 
 ;;;###autoload
 (defun erc-select-read-args ()
-  "Prompt the user for values of nick, server, port, and password."
+  "Prompt the user for values of nick, server, port, and password.
+With prefix arg, also prompt for user and full name."
   (require 'url-parse)
   (let* ((input (let ((d (erc-compute-server)))
                   (read-string (format "Server or URL (default is %S): " d)
@@ -2198,6 +2199,14 @@ erc-select-read-args
                    (let ((d (erc-compute-nick)))
                      (read-string (format "Nickname (default is %S): " d)
                                   nil 'erc-nick-history-list d))))
+         (user (and current-prefix-arg
+                    (let ((d (erc-compute-user (url-user url))))
+                      (read-string (format "User (default is %S): " d)
+                                   nil nil d))))
+         (full (and current-prefix-arg
+                    (let ((d (erc-compute-full-name (url-user url))))
+                      (read-string (format "Full name (default is %S): " d)
+                                   nil nil d))))
          (passwd (let* ((p (with-suppressed-warnings ((obsolete erc-password))
                              (or (url-password url) erc-password)))
                         (m (if p
@@ -2213,8 +2222,8 @@ erc-select-read-args
                       #'erc-open-tls-stream)))
     (when (and passwd (string= "" passwd))
       (setq passwd nil))
-    `( :server ,server :port ,port :nick ,nick
-       ,@(and passwd `(:password ,passwd))
+    `( :server ,server :port ,port :nick ,nick ,@(and user `(:user ,user))
+       ,@(and passwd `(:password ,passwd)) ,@(and full `(:full-name ,full))
        ,@(and erc-interactive-display
               `(buffer-display ,erc-interactive-display))
        ,@(and opener `(connect-function ,opener)))))
@@ -2321,8 +2330,8 @@ erc-tls
 
 When present, ID should be a symbol or a string to use for naming
 the server buffer and identifying the connection unequivocally.
-See info node `(erc) Network Identifier' for details.  Like USER
-and CLIENT-CERTIFICATE, this parameter cannot be specified
+See info node `(erc) Network Identifier' for details.  Like
+CLIENT-CERTIFICATE, this parameter cannot be specified
 interactively.
 
 \(fn &key SERVER PORT NICK USER PASSWORD FULL-NAME CLIENT-CERTIFICATE ID)"
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 91cdf2f1770..d05b0efe2ed 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -1086,7 +1086,18 @@ erc-select-read-args
                      (erc-select-read-args))
                    (list :server "[::1]"
                          :port 6667
-                         :nick "nick")))))
+                         :nick "nick"))))
+
+  (ert-info ("Extra args use URL nick by default")
+    (should (equal (ert-simulate-keys "nick:sesame@localhost:6667\r\r\r\r"
+                     (let ((current-prefix-arg '(4)))
+                       (erc-select-read-args)))
+                   (list :server "localhost"
+                         :port 6667
+                         :nick "nick"
+                         :user "nick"
+                         :password "sesame"
+                         :full-name "nick")))))
 
 (ert-deftest erc-tls ()
   (let (calls)
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-01-02  1:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-30 14:15 bug#60428: 29.0.60; ERC 5.4.1: Fix default-port regression in erc-select-read-args J.P.
     [not found] <87mt750ygt.fsf@neverwas.me>
2023-01-02  1:41 ` J.P.

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.