]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix byte-counting error in ‘format’
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 14 Nov 2019 22:42:39 +0000 (14:42 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 14 Nov 2019 22:44:42 +0000 (14:44 -0800)
Problem reported by Paul Pogonyshev (Bug#38191).
* src/editfns.c (styled_format): When checking for adjacent
%-sequences, use byte position rather than character position.
* test/src/editfns-tests.el (format-properties): Test for fix.

src/editfns.c
test/src/editfns-tests.el

index 1b33f3971106a61ce879b461a0e113137378d518..8fc866d391ffb2a3290b7dd70a586b0977ed957c 100644 (file)
@@ -3143,7 +3143,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
     /* The start and end bytepos in the output string.  */
     ptrdiff_t start, end;
 
-    /* The start of the spec in the format string.  */
+    /* The start bytepos of the spec in the format string.  */
     ptrdiff_t fbeg;
 
     /* Whether the argument is a string with intervals.  */
@@ -3954,7 +3954,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
                    {
                      position++;
                      if (fieldn < nspec
-                         && position > info[fieldn].fbeg
+                         && bytepos >= info[fieldn].fbeg
                          && translated == info[fieldn].start)
                        {
                          translated += info[fieldn].end - info[fieldn].start;
@@ -3976,7 +3976,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
                    {
                      position++;
                      if (fieldn < nspec
-                         && position > info[fieldn].fbeg
+                         && bytepos >= info[fieldn].fbeg
                          && translated == info[fieldn].start)
                        {
                          translated += info[fieldn].end - info[fieldn].start;
index a1060808f6699d80bf24a6aef7fdc5a58012fd8a..238fb409f0bf6f46661e9393cbba7b754f23e89e 100644 (file)
                                    (propertize "45" 'face 'italic)))
            #("012345    "
              0 2 (face bold) 2 4 (face underline) 4 10 (face italic))))
+  ;; Bug #38191
+  (should (ert-equal-including-properties
+           (format (propertize "‘foo’ %s bar" 'face 'bold) "xxx")
+           #("‘foo’ xxx bar" 0 13 (face bold))))
   ;; Bug #32404
   (should (ert-equal-including-properties
            (format (concat (propertize "%s" 'face 'bold)