summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/editfns.c13
-rw-r--r--test/src/editfns-tests.el11
2 files changed, 22 insertions, 2 deletions
diff --git a/src/editfns.c b/src/editfns.c
index b553a213e6c..fc5b6c117f5 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3304,8 +3304,17 @@ buffer_chars_equal (struct context *ctx,
eassert (pos_b >= BUF_BEGV (ctx->buffer_b));
eassert (pos_b < BUF_ZV (ctx->buffer_b));
- return BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_a, pos_a)
- == BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_b, pos_b);
+ ptrdiff_t bpos_a =
+ NILP (BVAR (ctx->buffer_a, enable_multibyte_characters))
+ ? pos_a
+ : buf_charpos_to_bytepos (ctx->buffer_a, pos_a);
+ ptrdiff_t bpos_b =
+ NILP (BVAR (ctx->buffer_b, enable_multibyte_characters))
+ ? pos_b
+ : buf_charpos_to_bytepos (ctx->buffer_b, pos_b);
+
+ return BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_a, bpos_a)
+ == BUF_FETCH_CHAR_AS_MULTIBYTE (ctx->buffer_b, bpos_b);
}
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index 714e92e5053..ec411ff773b 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -247,6 +247,17 @@
(buffer-string)
"foo bar baz qux"))))))
+(ert-deftest replace-buffer-contents-bug31837 ()
+ (switch-to-buffer "a")
+ (insert-char (char-from-name "SMILE"))
+ (insert "1234")
+ (switch-to-buffer "b")
+ (insert-char (char-from-name "SMILE"))
+ (insert "5678")
+ (replace-buffer-contents "a")
+ (should (equal (buffer-substring-no-properties (point-min) (point-max))
+ (concat (string (char-from-name "SMILE")) "1234"))))
+
(ert-deftest delete-region-undo-markers-1 ()
"Make sure we don't end up with freed markers reachable from Lisp."
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30931#40