aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-04-29 19:41:44 +0300
committerJuri Linkov2025-04-29 19:41:44 +0300
commit9d0595d8795fbd604c6429317daff4d6445f8904 (patch)
tree052d429fddaa6a0ea2a7a9b41cff7beb0dddb6d3
parent622825995204b7aae70b836c8e5e5d44385c401b (diff)
downloademacs-9d0595d8795fbd604c6429317daff4d6445f8904.tar.gz
emacs-9d0595d8795fbd604c6429317daff4d6445f8904.zip
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).
-rw-r--r--lisp/isearch.el16
-rw-r--r--test/lisp/isearch-tests.el24
2 files changed, 37 insertions, 3 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 5cde8092bde..b23f38077aa 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -4625,7 +4625,13 @@ defaults to the value of `isearch-search-fun-default' when nil."
4625 ;; Otherwise, try to search for the next property. 4625 ;; Otherwise, try to search for the next property.
4626 (unless beg 4626 (unless beg
4627 (setq beg (funcall next-fun old)) 4627 (setq beg (funcall next-fun old))
4628 (when beg (goto-char beg))) 4628 (when beg
4629 (if (or (null bound)
4630 (if isearch-forward
4631 (< beg bound)
4632 (> beg bound)))
4633 (goto-char beg)
4634 (setq beg nil))))
4629 ;; Non-nil `beg' means there are more properties. 4635 ;; Non-nil `beg' means there are more properties.
4630 (while (and beg (not found)) 4636 (while (and beg (not found))
4631 ;; Search for the end of the current property. 4637 ;; Search for the end of the current property.
@@ -4675,7 +4681,13 @@ defaults to the value of `isearch-search-fun-default' when nil."
4675 ;; Get the next text property. 4681 ;; Get the next text property.
4676 (unless found 4682 (unless found
4677 (setq beg (funcall next-fun end)) 4683 (setq beg (funcall next-fun end))
4678 (when beg (goto-char beg)))) 4684 (when beg
4685 (if (or (null bound)
4686 (if isearch-forward
4687 (< beg bound)
4688 (> beg bound)))
4689 (goto-char beg)
4690 (setq beg nil)))))
4679 (unless found (goto-char old)) 4691 (unless found (goto-char old))
4680 found)) 4692 found))
4681 4693
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 @@
247 (dolist (pos (append (reverse pairs) nil)) 247 (dolist (pos (append (reverse pairs) nil))
248 (should (eq (car pos) (isearch-search-string "foo$" nil t))) 248 (should (eq (car pos) (isearch-search-string "foo$" nil t)))
249 (should (equal (match-string 0) "foo")) 249 (should (equal (match-string 0) "foo"))
250 (when (cdr pos) (should (eq (cdr pos) (match-end 0))))))) 250 (when (cdr pos) (should (eq (cdr pos) (match-end 0))))))
251
252 ;; With BOUND arg (bug#78116)
253 (goto-char (point-min))
254 (let ((isearch-forward t)
255 (isearch-regexp nil)
256 (pos (car pairs)))
257 (should (eq (cdr pos) (isearch-search-string "foo" (cdr pos) t)))
258 (should (eq nil (isearch-search-string "foo" (cdr pos) t)))
259 ;; Start on the text property inside boundaries
260 (forward-char -1)
261 (should (eq nil (isearch-search-string "foo" (cdr pos) t))))
262
263 ;; With BOUND arg (bug#78116)
264 (goto-char (point-max))
265 (let ((isearch-forward nil)
266 (isearch-regexp nil)
267 (pos (car (last pairs))))
268 (should (eq (car pos) (isearch-search-string "foo" (car pos) t)))
269 (should (eq nil (isearch-search-string "foo" (car pos) t)))
270 ;; Start on the text property inside boundaries
271 (forward-char 1)
272 (should (eq nil (isearch-search-string "foo" (car pos) t)))))
251 273
252(ert-deftest isearch--test-search-fun-in-text-property () 274(ert-deftest isearch--test-search-fun-in-text-property ()
253 (let* ((pairs '((4 . 7) (11 . 14) (21 . 24))) 275 (let* ((pairs '((4 . 7) (11 . 14) (21 . 24)))