Subject: text-property-search-backward misses one-character regions

From: Nicolas Graner <[email-masked]>
Date: Tue, 01 Nov 2022 00:20:58 +0100

In Emacs 29.0.50, when a single character has a text property and you
try to find it with text-property-search-backward, the result
incorrectly includes previous characters without the property.

Example:

(with-current-buffer (generate-new-buffer "test")
  (insert "123456789")
  (put-text-property 3 4 'foo 'bar)
  (goto-char 6)
  (text-property-search-backward 'foo))

The returned value is
  #s(prop-match 1 4 nil)
instead of
  #s(prop-match 3 4 bar)
and the point in the test buffer is moved to position 1 instead of 3.

This incorrect behavior is the same if you replace (goto-char 6) with
(goto-char 5) or any other value greater than 4. However, the result is
correct with (goto-char 4), i.e. when the backward search starts one
position after the target character. This suggests an off-by-one error
in the code.

Hope this helps,
Nicolas