diff options
author | Štěpán Němec <stepnem@gmail.com> | 2020-03-07 18:26:44 +0100 |
---|---|---|
committer | Štěpán Němec <stepnem@gmail.com> | 2020-04-13 12:12:00 +0200 |
commit | 188bd80a903d34ef6a85b09e99890433e7adceb7 (patch) | |
tree | f8f32f801fcf61e0a4464bee9319c1ecc78e8943 /lisp/emacs-lisp | |
parent | c395ebaf2142b4a142262353f730fb7b1fcea710 (diff) | |
download | emacs-188bd80a903d34ef6a85b09e99890433e7adceb7.tar.gz emacs-188bd80a903d34ef6a85b09e99890433e7adceb7.tar.bz2 emacs-188bd80a903d34ef6a85b09e99890433e7adceb7.zip |
gnus-shorten-url: Improve and avoid args-out-of-range error
'gnus-shorten-url' (used by 'gnus-summary-browse-url') ignored
fragment identifiers and didn't check substring bounds, in some cases
leading to runtime errors, e.g.:
(gnus-shorten-url "https://some.url.with/path/and#also_a_long_target" 40)
;; => Lisp error: (args-out-of-range "/path/and" -18 nil)
This commit makes it account for #fragments and fixes faulty string
computation, reusing existing helper function. (bug#39980)
* lisp/vc/ediff-init.el (ediff-truncate-string-left): Rename to
'string-truncate-left' and move...
* lisp/emacs-lisp/subr-x.el (string-truncate-left): ...here.
All callers changed.
* lisp/gnus/gnus-sum.el (gnus-shorten-url): Fix args-out-of-range
error, don't drop #fragments, use 'string-truncate-left'.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 044c9aada0d..9f96ac50d1c 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -236,6 +236,15 @@ REGEXP defaults to \"[ \\t\\n\\r]+\"." TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"." (string-trim-left (string-trim-right string trim-right) trim-left)) +;;;###autoload +(defun string-truncate-left (string length) + "Truncate STRING to LENGTH, replacing initial surplus with \"...\"." + (let ((strlen (length string))) + (if (<= strlen length) + string + (setq length (max 0 (- length 3))) + (concat "..." (substring string (max 0 (- strlen 1 length))))))) + (defsubst string-blank-p (string) "Check whether STRING is either empty or only whitespace. The following characters count as whitespace here: space, tab, newline and |