aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNoam Postavsky2019-06-16 13:48:56 -0400
committerNoam Postavsky2019-06-22 19:25:44 -0400
commitf46b16b9fb00d341f222422a9514f5bd62f29971 (patch)
treee42e73ce40e790018f6a3cdf88af5bb141fb1d8a /lisp
parent96ebbf44b076b165943caefc1bbb0ff4c0f12b6b (diff)
downloademacs-f46b16b9fb00d341f222422a9514f5bd62f29971.tar.gz
emacs-f46b16b9fb00d341f222422a9514f5bd62f29971.zip
Make rcirc parsing more RFC2812 compliant (Bug#36233)
Do continue to allow multiple spaces between arguments, even though that is technically not allowed by the RFC. * lisp/net/rcirc.el (rcirc-process-server-response-1): Fix parsing of arguments which contain colons. * test/lisp/net/rcirc-tests.el: New test.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/net/rcirc.el27
1 files changed, 19 insertions, 8 deletions
diff --git a/lisp/net/rcirc.el b/lisp/net/rcirc.el
index 8926772b944..24084c828e1 100644
--- a/lisp/net/rcirc.el
+++ b/lisp/net/rcirc.el
@@ -774,22 +774,33 @@ Function is called with PROCESS, COMMAND, SENDER, ARGS and LINE.")
774 (rcirc-process-server-response-1 process text))) 774 (rcirc-process-server-response-1 process text)))
775 775
776(defun rcirc-process-server-response-1 (process text) 776(defun rcirc-process-server-response-1 (process text)
777 (if (string-match "^\\(:\\([^ ]+\\) \\)?\\([^ ]+\\) \\(.+\\)$" text) 777 ;; See https://tools.ietf.org/html/rfc2812#section-2.3.1. We're a
778 ;; bit more accepting than the RFC: We allow any non-space
779 ;; characters in the command name, multiple spaces between
780 ;; arguments, and allow the last argument to omit the leading ":",
781 ;; even if there are less than 15 arguments.
782 (if (string-match "^\\(:\\([^ ]+\\) \\)?\\([^ ]+\\)" text)
778 (let* ((user (match-string 2 text)) 783 (let* ((user (match-string 2 text))
779 (sender (rcirc-user-nick user)) 784 (sender (rcirc-user-nick user))
780 (cmd (match-string 3 text)) 785 (cmd (match-string 3 text))
781 (args (match-string 4 text)) 786 (cmd-end (match-end 3))
787 (args nil)
782 (handler (intern-soft (concat "rcirc-handler-" cmd)))) 788 (handler (intern-soft (concat "rcirc-handler-" cmd))))
783 (string-match "^\\([^:]*\\):?\\(.+\\)?$" args) 789 (cl-loop with i = cmd-end
784 (let* ((args1 (match-string 1 args)) 790 repeat 14
785 (args2 (match-string 2 args)) 791 while (eql i (string-match " +\\([^: ][^ ]*\\)" text i))
786 (args (delq nil (append (split-string args1 " " t) 792 do (progn (push (match-string 1 text) args)
787 (list args2))))) 793 (setq i (match-end 0)))
794 finally
795 (progn (if (eql i (string-match " +:?" text i))
796 (push (substring text (match-end 0)) args)
797 (cl-assert (= i (length text))))
798 (cl-callf nreverse args)))
788 (if (not (fboundp handler)) 799 (if (not (fboundp handler))
789 (rcirc-handler-generic process cmd sender args text) 800 (rcirc-handler-generic process cmd sender args text)
790 (funcall handler process sender args text)) 801 (funcall handler process sender args text))
791 (run-hook-with-args 'rcirc-receive-message-functions 802 (run-hook-with-args 'rcirc-receive-message-functions
792 process cmd sender args text))) 803 process cmd sender args text))
793 (message "UNHANDLED: %s" text))) 804 (message "UNHANDLED: %s" text)))
794 805
795(defvar rcirc-responses-no-activity '("305" "306") 806(defvar rcirc-responses-no-activity '("305" "306")