Subject: bug#79312: [PATCH] Fix parsing single-digit color codes in rcirc

From: Alcor <[email-masked]>
Date: Mon, 25 Aug 2025 21:27:17 +0200

Tags: patch

According to https://modern.ircdocs.horse/formatting#color IRC color
codes may consist of a single digit, e.g. ^C3IRC^C.

See https://modern.ircdocs.horse/formatting#examples for further
examples.

The provided two-liner patch relaxes the regexps used for parsing
accordingly so that the single-digit case is supported.

In GNU Emacs 30.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.41,
 cairo version 1.18.0) of 2025-08-15 built on lcy02-amd64-116
Repository revision: 32909ac267415e06a8b18a8b89827d7bbf180b58
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12302006
System Description: Ubuntu 24.04.2 LTS

Configured using:
 'configure --prefix=/snap/emacs/current/usr --with-x-toolkit=gtk3
 --without-xaw3d --with-modules --with-cairo
 --with-native-compilation=aot --without-pgtk --with-xinput2
 --with-tree-sitter 'CFLAGS=-isystem
 /build/emacs/parts/emacs/install/usr/include -isystem
 /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
 /build/emacs/stage/usr/include -O2' 'CPPFLAGS=-isystem
 /build/emacs/parts/emacs/install/usr/include -isystem
 /build/emacs/parts/emacs/install/usr/include/x86_64-linux-gnu -isystem
 /build/emacs/stage/usr/include'
 'LDFLAGS=-L/build/emacs/parts/emacs/install/lib
 -L/build/emacs/parts/emacs/install/usr/lib
 -L/build/emacs/parts/emacs/install/lib/x86_64-linux-gnu
 -L/build/emacs/parts/emacs/install/usr/lib/x86_64-linux-gnu
 -L/build/emacs/stage/usr/lib''

>From 178775ce346842f3a6b6baf3945b459cb3e06899 Mon Sep 17 00:00:00 2001
From: Alcor <[email-masked]>
Date: Mon, 25 Aug 2025 21:14:40 +0200
Subject: [PATCH] Fix parsing single-digit color codes in rcirc

* lisp/net/rcirc.el (rcirc-color-attributes)
(rcirc-remove-markup-codes): Handle single-digit color codes correctly.
---
 lisp/net/rcirc.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index bfa42ee..a7f1d8b 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -3130,7 +3130,7 @@ indicated by RESPONSE)."
   "Highlight IRC color-codes, indicated by ASCII control codes."
   (while (re-search-forward
           (rx #x03
-              (? (group (= 2 digit)) (? "," (group (= 2 digit))))
+              (? (group (** 1 2 digit)) (? "," (group (** 1 2 digit))))
               (*? nonl)
               (or #x03 #x0f eol))
           nil t)
@@ -3151,7 +3151,7 @@ indicated by RESPONSE)."
   "Remove ASCII control codes used to designate markup."
   (while (re-search-forward
           (rx (or #x02 #x1d #x1f #x1e #x11 #x0f
-                  (: #x03 (? (= 2 digit) (? "," (= 2 digit))))))
+                  (: #x03 (? (** 1 2 digit) (? "," (** 1 2 digit))))))
           nil t)
     (delete-region (match-beginning 0) (match-end 0))))
 
-- 
2.43.0