[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
fix/bug-48598 50b3aa88fc 11/27: Recognize ascii and strict CASEMAPPINGs
From: |
F. Jason Park |
Subject: |
fix/bug-48598 50b3aa88fc 11/27: Recognize ascii and strict CASEMAPPINGs in ERC |
Date: |
Fri, 8 Apr 2022 03:06:47 -0400 (EDT) |
branch: fix/bug-48598
commit 50b3aa88fcc91092ef6d261d561654756b527e6c
Author: F. Jason Park <jp@neverwas.me>
Commit: F. Jason Park <jp@neverwas.me>
Recognize ascii and strict CASEMAPPINGs in ERC
* lisp/erc/erc.el (erc-downcase, erc--casemapping-rfc1459-strict,
erc--casemapping-rfc1459): Add new translation tables for these two
mappings and use them.
* test/lisp/erc/erc-tests.el: Add test for `erc-downcase'.
---
lisp/erc/erc.el | 34 +++++++++++++++++++++++-----------
test/lisp/erc/erc-tests.el | 24 ++++++++++++++++++++++++
2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index 8fb84e418b..882956b596 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -382,18 +382,30 @@ erc-channel-user struct.")
"Hash table of users on the current server.
It associates nicknames with `erc-server-user' struct instances.")
+(defconst erc--casemapping-rfc1459
+ (make-translation-table
+ '((?\[ . ?\{) (?\] . ?\}) (?\\ . ?\|) (?~ . ?^))
+ (mapcar (lambda (c) (cons c (+ c 32))) "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
+
+(defconst erc--casemapping-rfc1459-strict
+ (make-translation-table
+ '((?\[ . ?\{) (?\] . ?\}) (?\\ . ?\|))
+ (mapcar (lambda (c) (cons c (+ c 32))) "ABCDEFGHIJKLMNOPQRSTUVWXYZ")))
+
(defun erc-downcase (string)
- "Convert STRING to IRC standard conforming downcase."
- (let ((s (downcase string))
- (c '((?\[ . ?\{)
- (?\] . ?\})
- (?\\ . ?\|)
- (?~ . ?^))))
- (save-match-data
- (while (string-match "[]\\[~]" s)
- (aset s (match-beginning 0)
- (cdr (assq (aref s (match-beginning 0)) c)))))
- s))
+ "Return a downcased copy of STRING with properties.
+Use the CASEMAPPING ISUPPORT parameter to determine the style."
+ (let* ((mapping (erc--get-isupport-entry 'CASEMAPPING 'single))
+ (inhibit-read-only t))
+ (if (equal mapping "ascii")
+ (downcase string)
+ (with-temp-buffer
+ (insert string)
+ (translate-region (point-min) (point-max)
+ (if (equal mapping "rfc1459-strict")
+ erc--casemapping-rfc1459-strict
+ erc--casemapping-rfc1459))
+ (buffer-string)))))
(defmacro erc-with-server-buffer (&rest body)
"Execute BODY in the current ERC server buffer.
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 3766202fe5..4fd04651ca 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -399,6 +399,30 @@
(should (= hooked 2))))
(should-not (cadr erc-server-005-functions)))
+(ert-deftest erc-downcase ()
+ (let ((erc--isupport-params (make-hash-table)))
+
+ (puthash 'PREFIX '("(ov)@+") erc--isupport-params)
+ (puthash 'BOT '("B") erc--isupport-params)
+
+ (ert-info ("ascii")
+ (puthash 'CASEMAPPING '("ascii") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob[m]`"))
+ (should (equal (erc-downcase "Tilde~") "tilde~" ))
+ (should (equal (erc-downcase "\\O/") "\\o/" )))
+
+ (ert-info ("rfc1459")
+ (puthash 'CASEMAPPING '("rfc1459") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob{m}`" ))
+ (should (equal (erc-downcase "Tilde~") "tilde^" ))
+ (should (equal (erc-downcase "\\O/") "|o/" )))
+
+ (ert-info ("rfc1459-strict")
+ (puthash 'CASEMAPPING '("rfc1459-strict") erc--isupport-params)
+ (should (equal (erc-downcase "Bob[m]`") "bob{m}`"))
+ (should (equal (erc-downcase "Tilde~") "tilde~" ))
+ (should (equal (erc-downcase "\\O/") "|o/" )))))
+
(ert-deftest erc-ring-previous-command-base-case ()
(ert-info ("Create ring when nonexistent and do nothing")
(let (erc-input-ring
- fix/bug-48598 57eedf46ae 04/27: Add some ERC test helpers, (continued)
- fix/bug-48598 57eedf46ae 04/27: Add some ERC test helpers, F. Jason Park, 2022/04/08
- fix/bug-48598 911481d449 13/27: Add helper to determine local channels in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 eee86bc7d7 16/27: Add ERC test server and related resources, F. Jason Park, 2022/04/08
- fix/bug-48598 7cb4eec8a1 23/27: SQUASH-ME: Add ERC test scenarios for identity-aware autojoin, F. Jason Park, 2022/04/08
- fix/bug-48598 447bc23d7b 21/27: SQUASH-ME: Add ERC scenarios for identity-aware msg handlers, F. Jason Park, 2022/04/08
- fix/bug-48598 a999ff61fa 19/27: Register erc-kill-buffer-function locally, F. Jason Park, 2022/04/08
- fix/bug-48598 e0bf4383d7 24/27: Standardize auth-source queries in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 1978c3178c 10/27: Update ISUPPORT handling in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 6ee4329b46 02/27: Initialize erc-server-filter-data in erc-backend, F. Jason Park, 2022/04/08
- fix/bug-48598 3c6694d114 20/27: Don't call erc-auto-query twice on PRIVMSG, F. Jason Park, 2022/04/08
- fix/bug-48598 50b3aa88fc 11/27: Recognize ascii and strict CASEMAPPINGs in ERC,
F. Jason Park <=
- fix/bug-48598 f9794dea43 15/27: Discourage ill-defined use of buffer targets in ERC, F. Jason Park, 2022/04/08
- fix/bug-48598 bb117dfacb 05/27: [SQUASH-ME] Remove duplicate ERC prompt on reconnect, F. Jason Park, 2022/04/08
- fix/bug-48598 c25371f9d7 08/27: Don't set erc-server-announced-name unless known, F. Jason Park, 2022/04/08
- fix/bug-48598 8558f9434a 12/27: Make ERC respect spaces in server passwords, F. Jason Park, 2022/04/08
- fix/bug-48598 a9ef01ec76 06/27: Customize displaying of ERC buffers on reconnect, F. Jason Park, 2022/04/08
- fix/bug-48598 eef4fa00e8 01/27: Rework mutual dependency between erc and erc-backend, F. Jason Park, 2022/04/08
- fix/bug-48598 31030f2568 14/27: Add eventual replacement for erc-default-recipients, F. Jason Park, 2022/04/08
- fix/bug-48598 6ece132c35 09/27: Require erc-networks in erc.el, F. Jason Park, 2022/04/08
- fix/bug-48598 346381ffe5 17/27: Address long-standing ERC buffer-naming issues, F. Jason Park, 2022/04/08
- fix/bug-48598 bd8efa668b 18/27: SQUASH-ME: Add user-oriented test scenarios for ERC, F. Jason Park, 2022/04/08