From: Juri Linkov Date: Tue, 29 Apr 2025 16:41:44 +0000 (+0300) Subject: Fix invalid search bound in 'search-within-boundaries'. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=fcd0333a620a0a29f18195ae32793969e5e7ed7b;p=emacs.git 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). (cherry picked from commit 9d0595d8795fbd604c6429317daff4d6445f8904) --- diff --git a/lisp/isearch.el b/lisp/isearch.el index 19d13057eff..cfb6f4c50a3 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -4585,7 +4585,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. @@ -4635,7 +4641,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)) diff --git a/test/lisp/isearch-tests.el b/test/lisp/isearch-tests.el index 301108afbe4..3b2c070d003 100644 --- a/test/lisp/isearch-tests.el +++ b/test/lisp/isearch-tests.el @@ -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)))