]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix invalid search bound in 'search-within-boundaries'.
authorJuri Linkov <juri@linkov.net>
Tue, 29 Apr 2025 16:41:44 +0000 (19:41 +0300)
committerEshel Yaron <me@eshelyaron.com>
Thu, 1 May 2025 07:23:19 +0000 (09:23 +0200)
* 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)

lisp/isearch.el
test/lisp/isearch-tests.el

index 19d13057eff3cbc7ba5b4e918c6cf359ddfd064d..cfb6f4c50a326a2d79de0abfa745ade316d1d7fe 100644 (file)
@@ -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))
 
index 301108afbe4e58234c22fc1c8e7c1ba0d9d7191f..3b2c070d003e670c24d18ffe86bb30d9360894da 100644 (file)
     (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)))