1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

Fix invalid search bound in 'search-within-boundaries'.

* lisp/isearch.el (search-within-boundaries): Don't go over BOUND.

* test/lisp/isearch-tests.el (isearch--test-search-within-boundaries):
Test with the BOUND arg as well (bug#78116).
This commit is contained in:
Juri Linkov 2025-04-29 19:41:44 +03:00
parent 6228259952
commit 9d0595d879
2 changed files with 37 additions and 3 deletions

View file

@ -4625,7 +4625,13 @@ defaults to the value of `isearch-search-fun-default' when nil."
;; Otherwise, try to search for the next property.
(unless beg
(setq beg (funcall next-fun old))
(when beg (goto-char beg)))
(when beg
(if (or (null bound)
(if isearch-forward
(< beg bound)
(> beg bound)))
(goto-char beg)
(setq beg nil))))
;; Non-nil `beg' means there are more properties.
(while (and beg (not found))
;; Search for the end of the current property.
@ -4675,7 +4681,13 @@ defaults to the value of `isearch-search-fun-default' when nil."
;; Get the next text property.
(unless found
(setq beg (funcall next-fun end))
(when beg (goto-char beg))))
(when beg
(if (or (null bound)
(if isearch-forward
(< beg bound)
(> beg bound)))
(goto-char beg)
(setq beg nil)))))
(unless found (goto-char old))
found))

View file

@ -247,7 +247,29 @@
(dolist (pos (append (reverse pairs) nil))
(should (eq (car pos) (isearch-search-string "foo$" nil t)))
(should (equal (match-string 0) "foo"))
(when (cdr pos) (should (eq (cdr pos) (match-end 0)))))))
(when (cdr pos) (should (eq (cdr pos) (match-end 0))))))
;; With BOUND arg (bug#78116)
(goto-char (point-min))
(let ((isearch-forward t)
(isearch-regexp nil)
(pos (car pairs)))
(should (eq (cdr pos) (isearch-search-string "foo" (cdr pos) t)))
(should (eq nil (isearch-search-string "foo" (cdr pos) t)))
;; Start on the text property inside boundaries
(forward-char -1)
(should (eq nil (isearch-search-string "foo" (cdr pos) t))))
;; With BOUND arg (bug#78116)
(goto-char (point-max))
(let ((isearch-forward nil)
(isearch-regexp nil)
(pos (car (last pairs))))
(should (eq (car pos) (isearch-search-string "foo" (car pos) t)))
(should (eq nil (isearch-search-string "foo" (car pos) t)))
;; Start on the text property inside boundaries
(forward-char 1)
(should (eq nil (isearch-search-string "foo" (car pos) t)))))
(ert-deftest isearch--test-search-fun-in-text-property ()
(let* ((pairs '((4 . 7) (11 . 14) (21 . 24)))