1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Really fix off-by-one in erc--get-inserted-msg-bounds

* lisp/erc/erc.el (erc--get-inserted-msg-bounds): Account for
`previous-single-property-change' returning a position adjacent to
that with an actual changed value.  The prior attempt at addressing
this was insufficient.
* test/lisp/erc/erc-tests.el (erc--get-inserted-msg-bounds): New test.
; * test/lisp/erc/resources/base/local-modules/second.eld: Timeout.
; * test/lisp/erc/resources/base/local-modules/third.eld: Timeout.
This commit is contained in:
F. Jason Park 2023-11-03 16:07:20 -07:00
parent 0b5e2ce761
commit fb578ddfb2
4 changed files with 57 additions and 5 deletions

View file

@ -3026,16 +3026,19 @@ stored value. Otherwise, return the stored value."
"Return the bounds of a message in an ERC buffer.
Return ONLY one side when the first arg is `end' or `beg'. With
POINT, search from POINT instead of `point'."
;; TODO add edebug spec.
`(let* ((point ,(or point '(point)))
(at-start-p (get-text-property point 'erc-msg)))
(and-let*
(,@(and (member only '(nil 'beg))
(,@(and (member only '(nil beg 'beg))
'((b (or (and at-start-p point)
(and-let*
((p (previous-single-property-change point
'erc-msg)))
(if (= p (1- point)) p (1- p)))))))
,@(and (member only '(nil 'end))
(if (= p (1- point))
(if (get-text-property p 'erc-msg) p (1- p))
(1- p)))))))
,@(and (member only '(nil end 'end))
'((e (1- (next-single-property-change
(if at-start-p (1+ point) point)
'erc-msg nil erc-insert-marker))))))

View file

@ -1432,6 +1432,55 @@
(should-not calls))))))
(ert-deftest erc--get-inserted-msg-bounds ()
(erc-mode)
(erc--initialize-markers (point) nil)
(let ((parsed (make-erc-response :unparsed ":bob PRIVMSG #chan :hi"
:sender "bob"
:command "PRIVMSG"
:command-args (list "#chan" "hi")
:contents "hi"))
(erc--msg-prop-overrides '((erc-ts . 0))))
(erc-display-message parsed nil (current-buffer)
(erc-format-privmessage "bob" "hi" nil t)))
(goto-char 3)
(should (looking-at "<bob> hi"))
(goto-char 11)
(should (looking-back "<bob> hi"))
(ert-info ("Parameter `only' being `beg'")
(dolist (i (number-sequence 3 11))
(goto-char i)
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (= 3 (erc--get-inserted-msg-bounds 'beg)))))
(ert-info ("Parameter `point'")
(dolist (i (number-sequence 3 11))
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (= 3 (erc--get-inserted-msg-bounds 'beg i)))))))
(ert-info ("Parameter `only' being `end'")
(dolist (i (number-sequence 3 11))
(goto-char i)
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (= 11 (erc--get-inserted-msg-bounds 'end)))))
(ert-info ("Parameter `point'")
(dolist (i (number-sequence 3 11))
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (= 11 (erc--get-inserted-msg-bounds 'end i)))))))
(ert-info ("Parameter `only' being nil")
(dolist (i (number-sequence 3 11))
(goto-char i)
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (equal '(3 . 11) (erc--get-inserted-msg-bounds nil)))))
(ert-info ("Parameter `point'")
(dolist (i (number-sequence 3 11))
(ert-info ((format "At %d (%c)" i (char-after i)))
(should (equal '(3 . 11) (erc--get-inserted-msg-bounds nil i))))))))
(ert-deftest erc--delete-inserted-message ()
(erc-mode)
(erc--initialize-markers (point) nil)

View file

@ -41,7 +41,7 @@
(0.07 ":alice!~u@2fzfcku68ehqa.irc PRIVMSG #chan :bob: To you that know them not. This to my mother.")
(0.00 ":bob!~u@2fzfcku68ehqa.irc PRIVMSG #chan :alice: Some enigma, some riddle: come, thy l'envoy; begin."))
((quit 1 "QUIT :\2ERC\2")
((quit 10 "QUIT :\2ERC\2")
(0.03 ":tester`!~u@u9iqi96sfwk9s.irc QUIT"))
((drop 0 DROP))

View file

@ -37,7 +37,7 @@
(0.00 ":alice!~u@2fzfcku68ehqa.irc PRIVMSG #chan :bob: No remedy, my lord, when walls are so wilful to hear without warning.")
(0.01 ":bob!~u@2fzfcku68ehqa.irc PRIVMSG #chan :alice: Let our reciprocal vows be remembered. You have many opportunities to cut him off; if your will want not, time and place will be fruitfully offered. There is nothing done if he return the conqueror; then am I the prisoner, and his bed my gaol; from the loathed warmth whereof deliver me, and supply the place for your labor."))
((quit 1 "QUIT :\2ERC\2")
((quit 10 "QUIT :\2ERC\2")
(0.03 ":tester`!~u@u9iqi96sfwk9s.irc QUIT :Quit"))
((drop 0 DROP))