Allow login to contain NUH delimiters in erc-parse-user

* lisp/erc/erc.el (erc--parse-user-regexp-legacy,
erc--parse-user-regexp-pedantic): New constants.  The first is the
original pattern that matches across line endings.  The second
disallows multiline strings and interprets excess delimiting
characters as part of the middle, "user" component as per RFC1459.
The latter distinction is largely academic because most servers reject
such logins anyway, but bridges to other protocols and future
extensions may need to exploit this for novel uses.
(erc--parse-user-regexp): New variable, currently set to
`erc--parse-user-regexp-legacy'.
(erc-parse-user): Keep original pattern as default, but do so
indirectly via `erc--parse-user-regexp'.
* test/lisp/erc/erc-tests.el (erc-parse-user): New test.
This commit is contained in:
F. Jason Park 2023-09-01 20:05:35 -07:00
parent b5df39e924
commit c96a626dce
2 changed files with 44 additions and 1 deletions

View file

@ -6316,12 +6316,22 @@ EmacsSpeak support."
(defalias 'erc-list 'ensure-list)
(defconst erc--parse-user-regexp-pedantic
(rx bot (group (* (not (any "!\r\n"))))
"!" (group (* nonl))
"@" (group (* nonl)) eot))
(defconst erc--parse-user-regexp-legacy
"^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$")
(defvar erc--parse-user-regexp erc--parse-user-regexp-legacy)
(defun erc-parse-user (string)
"Parse STRING as a user specification (nick!login@host).
Return a list of the three separate tokens."
(cond
((string-match "^\\([^!\n]*\\)!\\([^@\n]*\\)@\\(.*\\)$" string)
((string-match erc--parse-user-regexp string)
(list (match-string 1 string)
(match-string 2 string)
(match-string 3 string)))

View file

@ -576,6 +576,39 @@
(setq erc-lurker-ignore-chars "_-`") ; set of chars, not character alts
(should (string= "nick" (erc-lurker-maybe-trim "nick-_`")))))
(ert-deftest erc-parse-user ()
(should (equal erc--parse-user-regexp erc--parse-user-regexp-legacy))
(should (equal '("" "" "") (erc-parse-user "!@")))
(should (equal '("" "!" "") (erc-parse-user "!!@")))
(should (equal '("" "" "@") (erc-parse-user "!@@")))
(should (equal '("" "!" "@") (erc-parse-user "!!@@")))
(should (equal '("abc" "" "") (erc-parse-user "abc")))
(should (equal '("" "123" "fake") (erc-parse-user "!123@fake")))
(should (equal '("abc" "" "123") (erc-parse-user "abc!123")))
(should (equal '("abc" "123" "fake") (erc-parse-user "abc!123@fake")))
(should (equal '("abc" "!123" "@xy") (erc-parse-user "abc!!123@@xy")))
(should (equal '("de" "fg" "xy") (erc-parse-user "abc\nde!fg@xy")))
(ert-info ("`erc--parse-user-regexp-pedantic'")
(let ((erc--parse-user-regexp erc--parse-user-regexp-pedantic))
(should (equal '("" "" "") (erc-parse-user "!@")))
(should (equal '("" "!" "") (erc-parse-user "!!@")))
(should (equal '("" "@" "") (erc-parse-user "!@@")))
(should (equal '("" "!@" "") (erc-parse-user "!!@@")))
(should (equal '("abc" "" "") (erc-parse-user "abc")))
(should (equal '("" "123" "fake") (erc-parse-user "!123@fake")))
(should (equal '("abc" "" "123") (erc-parse-user "abc!123")))
(should (equal '("abc" "123" "fake") (erc-parse-user "abc!123@fake")))
(should (equal '("abc" "!123@" "xy") (erc-parse-user "abc!!123@@xy")))
(should (equal '("de" "" "fg@xy") (erc-parse-user "abc\nde!fg@xy"))))))
(ert-deftest erc--parse-isupport-value ()
(should (equal (erc--parse-isupport-value "a,b") '("a" "b")))
(should (equal (erc--parse-isupport-value "a,b,c") '("a" "b" "c")))