]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix trailing args bug in erc-d-i--parse-message
authorF. Jason Park <jp@neverwas.me>
Sat, 12 Oct 2024 21:33:25 +0000 (14:33 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 22 Oct 2024 18:54:58 +0000 (20:54 +0200)
* test/lisp/erc/resources/erc-d/erc-d-i.el: Require `subr-x'.
(erc-d-i--parse-message): Populate `contents' slot when lone trailing
arg lacks a preceding colon.
* test/lisp/erc/resources/erc-d/erc-d-tests.el (erc-d-i--parse-message):
Fix expected result.
(erc-d-i--parse-message/privmsg): New test.

(cherry picked from commit a5b2de8b54c3a2d7dcb84f7697e18b2257959dfc)

test/lisp/erc/resources/erc-d/erc-d-i.el
test/lisp/erc/resources/erc-d/erc-d-tests.el

index 219ab6d63f0e76f55f469eec0355b2949f91b497..97cd56408ce4b73b5a2c17905ed0021b3955cfd3 100644 (file)
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'cl-lib)
+(require 'subr-x)
 
 (cl-defstruct (erc-d-i-message (:conc-name erc-d-i-message.))
   "Identical to `erc-response'.
@@ -101,18 +102,19 @@ With DECODE, decode as UTF-8 text."
     (setq s (decode-coding-string s 'utf-8 t)))
   (let ((mes (make-erc-d-i-message :unparsed s :compat (not decode)))
         tokens)
-    (when-let* (((not (string-empty-p s)))
-                ((eq ?@ (aref s 0)))
-                (m (string-match " " s))
-                (u (substring s 1 m)))
+    (when-let (((not (string-empty-p s)))
+               ((eq ?@ (aref s 0)))
+               (m (string-match " " s))
+               (u (substring s 1 m)))
       (setf (erc-d-i-message.tags mes) (erc-d-i--validate-tags u)
             s (substring s (1+ m))))
-    (if-let* ((m (string-match " :" s))
-              (other-toks (split-string (substring s 0 m) " " t))
-              (rest (substring s (+ 2 m))))
+    (if-let ((m (string-search " :" s))
+             (other-toks (split-string (substring s 0 m) " " t))
+             (rest (substring s (+ 2 m))))
         (setf (erc-d-i-message.contents mes) rest
               tokens (nconc other-toks (list rest)))
-      (setq tokens (split-string s " " t " ")))
+      (setf tokens (split-string s " " t " ")
+            (erc-d-i-message.contents mes) (car (last tokens))))
     (when (and tokens (eq ?: (aref (car tokens) 0)))
       (setf (erc-d-i-message.sender mes) (substring (pop tokens) 1)))
     (setf (erc-d-i-message.command mes) (or (pop tokens) "")
index 63d304907eac9098252d5f9cd3e92b3de5e35ec8..a626ddd8edc14987200d2e47b4bba2f0916dbe9b 100644 (file)
                   'decode))
       (should-not (erc-d-i-message.compat ours))
       (should (equal (erc-d-i-message.command-args ours) '("#chàn")))
-      (should (equal (erc-d-i-message.contents ours) ""))
+      (should (equal (erc-d-i-message.contents ours) "#chàn"))
       (should (equal (erc-d-i-message.tags ours) '((foo . "çedilla")))))))
 
+(ert-deftest erc-d-i--parse-message/privmsg ()
+  (dolist (raw '(":Bob!~bob@gnu.org PRIVMSG #chan :one two"
+                 ":Bob!~bob@gnu.org PRIVMSG #chan one"
+                 ":Bob!~bob@gnu.org PRIVMSG #chan : "
+                 ":Bob!~bob@gnu.org PRIVMSG #chan :"
+                 "@account=bob :Bob!~bob@gnu.org PRIVMSG #chan one"
+                 "@foo=bar;baz :Bob!~bob@gnu.org PRIVMSG #chan :one"))
+    (dolist (slot '(unparsed
+                    sender
+                    command
+                    command-args
+                    contents
+                    tags))
+      (let ((ours (erc-d-i--parse-message raw))
+            (orig (erc-d-tests--parse-message-upstream raw)))
+        (ert-info ((format "slot: `%s', orig: %S, ours: %S"
+                           slot orig ours))
+          (if (eq slot 'tags)
+              (should (equal (erc-response.tags orig)
+                             (mapcar (pcase-lambda (`(,key . ,value))
+                                       (if value
+                                           (list (symbol-name key) value)
+                                         (list (symbol-name key))))
+                                     (reverse (erc-d-i-message.tags ours)))))
+            (should
+             (equal (cl-struct-slot-value 'erc-d-i-message slot ours)
+                    (cl-struct-slot-value 'erc-response slot orig)))))))))
+
 (ert-deftest erc-d-i--unescape-tag-value ()
   (should (equal (erc-d-i--unescape-tag-value
                   "\\sabc\\sdef\\s\\sxyz\\s")