diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2022-07-23 08:55:20 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2022-07-23 08:58:53 +0200 |
commit | 51f5c4b773e11dd50f9fc6887362324b6d4dc755 (patch) | |
tree | 6ab881dc983d3dab010fd91d7069bbf36b6f9a03 /lisp/emacs-lisp | |
parent | 33602132acdf0ff9148aaeea32423c683529f039 (diff) | |
download | emacs-51f5c4b773e11dd50f9fc6887362324b6d4dc755.tar.gz emacs-51f5c4b773e11dd50f9fc6887362324b6d4dc755.tar.bz2 emacs-51f5c4b773e11dd50f9fc6887362324b6d4dc755.zip |
Fix off-by-one error in string-truncate-left
* lisp/emacs-lisp/subr-x.el (string-truncate-left): Fix off-by-one
error (bug#56685).
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 5037ae47e83..d5d7bfeb6f5 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -107,12 +107,16 @@ characters; nil stands for the empty string." ;;;###autoload (defun string-truncate-left (string length) - "Truncate STRING to LENGTH, replacing initial surplus with \"...\"." + "If STRING is longer than LENGTH, return a truncated version. +When truncating, \"...\" is always prepended to the string, so +the resulting string may be longer than the original if LENGTH is +3 or smaller." (let ((strlen (length string))) (if (<= strlen length) string (setq length (max 0 (- length 3))) - (concat "..." (substring string (max 0 (- strlen 1 length))))))) + (concat "..." (substring string (min (1- strlen) + (max 0 (- strlen length)))))))) (defsubst string-blank-p (string) "Check whether STRING is either empty or only whitespace. |