aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2019-11-14 14:42:39 -0800
committerPaul Eggert2019-11-14 14:44:42 -0800
commitc2cd8e6265b78a5f0be3335ea6d8868e80814db0 (patch)
tree0934435db848e080e14d46fa823456145616506b
parent2241f7ca7adb8aa7d785174dec0280a07cd16479 (diff)
downloademacs-c2cd8e6265b78a5f0be3335ea6d8868e80814db0.tar.gz
emacs-c2cd8e6265b78a5f0be3335ea6d8868e80814db0.zip
Fix byte-counting error in ‘format’
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.
-rw-r--r--src/editfns.c6
-rw-r--r--test/src/editfns-tests.el4
2 files changed, 7 insertions, 3 deletions
diff --git a/src/editfns.c b/src/editfns.c
index 1b33f397110..8fc866d391f 100644
--- a/src/editfns.c
+++ b/src/editfns.c
@@ -3143,7 +3143,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3143 /* The start and end bytepos in the output string. */ 3143 /* The start and end bytepos in the output string. */
3144 ptrdiff_t start, end; 3144 ptrdiff_t start, end;
3145 3145
3146 /* The start of the spec in the format string. */ 3146 /* The start bytepos of the spec in the format string. */
3147 ptrdiff_t fbeg; 3147 ptrdiff_t fbeg;
3148 3148
3149 /* Whether the argument is a string with intervals. */ 3149 /* Whether the argument is a string with intervals. */
@@ -3954,7 +3954,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3954 { 3954 {
3955 position++; 3955 position++;
3956 if (fieldn < nspec 3956 if (fieldn < nspec
3957 && position > info[fieldn].fbeg 3957 && bytepos >= info[fieldn].fbeg
3958 && translated == info[fieldn].start) 3958 && translated == info[fieldn].start)
3959 { 3959 {
3960 translated += info[fieldn].end - info[fieldn].start; 3960 translated += info[fieldn].end - info[fieldn].start;
@@ -3976,7 +3976,7 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
3976 { 3976 {
3977 position++; 3977 position++;
3978 if (fieldn < nspec 3978 if (fieldn < nspec
3979 && position > info[fieldn].fbeg 3979 && bytepos >= info[fieldn].fbeg
3980 && translated == info[fieldn].start) 3980 && translated == info[fieldn].start)
3981 { 3981 {
3982 translated += info[fieldn].end - info[fieldn].start; 3982 translated += info[fieldn].end - info[fieldn].start;
diff --git a/test/src/editfns-tests.el b/test/src/editfns-tests.el
index a1060808f66..238fb409f0b 100644
--- a/test/src/editfns-tests.el
+++ b/test/src/editfns-tests.el
@@ -90,6 +90,10 @@
90 (propertize "45" 'face 'italic))) 90 (propertize "45" 'face 'italic)))
91 #("012345 " 91 #("012345 "
92 0 2 (face bold) 2 4 (face underline) 4 10 (face italic)))) 92 0 2 (face bold) 2 4 (face underline) 4 10 (face italic))))
93 ;; Bug #38191
94 (should (ert-equal-including-properties
95 (format (propertize "‘foo’ %s bar" 'face 'bold) "xxx")
96 #("‘foo’ xxx bar" 0 13 (face bold))))
93 ;; Bug #32404 97 ;; Bug #32404
94 (should (ert-equal-including-properties 98 (should (ert-equal-including-properties
95 (format (concat (propertize "%s" 'face 'bold) 99 (format (concat (propertize "%s" 'face 'bold)