emacs-31 ed1a2e82390: Fix text-property-search-backward skipping one character regions

Sean Whitton <[email protected]> Wed, 5 Aug 2026 07:29:13 -0400 (EDT)
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: emacs-31
commit ed1a2e82390318a0e223e75d62ead1b4deff8585
Author: Sean Whitton <[email protected]>
Commit: Sean Whitton <[email protected]>

    Fix text-property-search-backward skipping one character regions
    
    * lisp/emacs-lisp/text-property-search.el
    (text-property-search-backward)
    (text-property--find-end-backward): Fix skipping one character
    non-matching regions (bug#81539).
    * test/lisp/emacs-lisp/text-property-search-tests.el
    (text-property-setup): Make one of the propertized regions one
    character long to test bug#81539.
    (text-property-search-forward-bold-nil)
    (text-property-search-forward-nil-nil)
    (text-property-search-backward-bold-nil)
    (text-property-search-backward-nil-nil)
    (text-property-search-backward-prop-match-match-face-nil-nil)
    (text-property-search-backward-prop-match-match-face-italic-t)
    (text-property-search-backward-prop-match-match-face-italic-nil):
    Update tests.
---
 lisp/emacs-lisp/text-property-search.el            | 10 +++++-----
 test/lisp/emacs-lisp/text-property-search-tests.el | 16 ++++++++--------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/lisp/emacs-lisp/text-property-search.el b/lisp/emacs-lisp/text-property-search.el
index f7709b27f31..4396a1212f8 100644
--- a/lisp/emacs-lisp/text-property-search.el
+++ b/lisp/emacs-lisp/text-property-search.el
@@ -174,12 +174,12 @@ and if a matching region is found, place point at the start of the region."
             (progn
               (goto-char origin)
               (setq ended t))
-          (goto-char (1- pos))
-          (if (text-property--match-p value (get-text-property (point) property)
+          (goto-char pos)
+          (if (text-property--match-p value (get-text-property (1- (point)) property)
                                       predicate)
               (setq ended
                     (text-property--find-end-backward
-                     (point) property value predicate))
+                     (1- (point)) property value predicate))
             ;; Skip past this section of non-matches.
             (setq pos (previous-single-property-change (point) property))
             (unless pos
@@ -203,9 +203,9 @@ and if a matching region is found, place point at the start of the region."
                   (goto-char (point-min))
                   (setq end (point)
                         ended t))
-              (goto-char (1- end))
+              (goto-char end)
               (unless (text-property--match-p
-                       value (get-text-property (point) property) predicate)
+                       value (get-text-property (1- (point)) property) predicate)
                 (goto-char end)
                 (setq ended t)))))
       ;; End this at the first place the property changes value.
diff --git a/test/lisp/emacs-lisp/text-property-search-tests.el b/test/lisp/emacs-lisp/text-property-search-tests.el
index 57d7f272b80..4fe90d1b41b 100644
--- a/test/lisp/emacs-lisp/text-property-search-tests.el
+++ b/test/lisp/emacs-lisp/text-property-search-tests.el
@@ -36,7 +36,7 @@
           " and this is "
           (propertize "italic1" 'face 'italic)
           (propertize "bold2" 'face 'bold)
-          (propertize "italic2" 'face 'italic)
+          (propertize "i" 'face 'italic) ; One char long to test bug#81539.
           " at the end")
   (goto-char (point-min)))
 
@@ -59,7 +59,7 @@
 
 (ert-deftest text-property-search-forward-bold-nil ()
   (with-test (text-property-search-forward 'face 'bold nil)
-             '("This is " " and this is italic1" "italic2 at the end")))
+             '("This is " " and this is italic1" "i at the end")))
 
 (ert-deftest text-property-search-forward-nil-t ()
   (with-test (text-property-search-forward 'face nil t)
@@ -67,7 +67,7 @@
 
 (ert-deftest text-property-search-forward-nil-nil ()
   (with-test (text-property-search-forward 'face nil nil)
-             '("bold1" "italic1" "bold2" "italic2")))
+             '("bold1" "italic1" "bold2" "i")))
 
 (ert-deftest text-property-search-forward-partial-bold-t ()
   (with-test (text-property-search-forward 'face 'bold t)
@@ -87,7 +87,7 @@
 
 (ert-deftest text-property-search-backward-bold-nil ()
   (with-test (text-property-search-backward 'face 'bold nil)
-             '( "italic2 at the end" " and this is italic1" "This is ")
+             '("i at the end" " and this is italic1" "This is ")
              (point-max)))
 
 (ert-deftest text-property-search-backward-nil-t ()
@@ -97,7 +97,7 @@
 
 (ert-deftest text-property-search-backward-nil-nil ()
   (with-test (text-property-search-backward 'face nil nil)
-             '("italic2" "bold2" "italic1" "bold1")
+             '("i" "bold2" "italic1" "bold1")
              (point-max)))
 
 (ert-deftest text-property-search-backward-partial-bold-t ()
@@ -138,19 +138,19 @@
 (ert-deftest text-property-search-backward-prop-match-match-face-nil-nil ()
   (with-match-test
    (text-property-search-backward 'face nil nil)
-   39 46 'italic
+   39 40 'italic
    (point-max)))
 
 (ert-deftest text-property-search-backward-prop-match-match-face-italic-t ()
   (with-match-test
    (text-property-search-backward 'face 'italic t)
-   39 46 'italic
+   39 40 'italic
    (point-max)))
 
 (ert-deftest text-property-search-backward-prop-match-match-face-italic-nil ()
   (with-match-test
    (text-property-search-backward 'face 'italic nil)
-   46 57 nil
+   40 51 nil
    (point-max)))