From: "Štěpán Němec" <stepnem@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 39980@debbugs.gnu.org
Subject: bug#39980: [PATCH] gnus-shorten-url: Improve and avoid args-out-of-range error
Date: Sun, 12 Apr 2020 22:02:18 +0200 [thread overview]
Message-ID: <87d08cbhh1.fsf@gmail.com> (raw)
In-Reply-To: <834ktolqks.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 12 Apr 2020 17:35:31 +0300")
[-- Attachment #1: Type: text/plain, Size: 334 bytes --]
On Sun, 12 Apr 2020 17:35:31 +0300
Eli Zaretskii wrote:
> Let's just come up with a local change in gnus-sum, for the emacs-27
> branch, okay?
OK. I think the pat(c)h of least resistence would be as follows
(everything just the same as for master, but with the helper function
localized to gnus-sum and no changes to other files):
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-gnus-shorten-url-Improve-and-avoid-args-out-of-range.patch --]
[-- Type: text/x-patch, Size: 2525 bytes --]
From 9fd1f20078220c17f9e954b556c6b770ca70961a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem@gmail.com>
Date: Sun, 12 Apr 2020 19:57:59 +0200
Subject: [PATCH] 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. (bug#39980)
; Do not merge to master, where the helper is put to subr-x.el.
* lisp/gnus/gnus-sum.el (gnus--string-truncate-left): New helper
function (copied from 'ediff-truncate-string-left').
(gnus-shorten-url): Use it and don't drop #fragments.
---
lisp/gnus/gnus-sum.el | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index a40e563e75..9b11d5878d 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -9493,16 +9493,26 @@ gnus-collect-urls
(push primary urls))
(delete-dups urls)))
+;; cf. `ediff-truncate-string-left', to become `string-truncate-left'
+;; in Emacs 28
+(defun gnus--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)))))))
+
(defun gnus-shorten-url (url max)
- "Return an excerpt from URL."
+ "Return an excerpt from URL not exceeding MAX characters."
(if (<= (length url) max)
url
- (let ((parsed (url-generic-parse-url url)))
- (concat (url-host parsed)
- "..."
- (substring (url-filename parsed)
- (- (length (url-filename parsed))
- (max (- max (length (url-host parsed))) 0)))))))
+ (let* ((parsed (url-generic-parse-url url))
+ (host (url-host parsed))
+ (rest (concat (url-filename parsed)
+ (when-let ((target (url-target parsed)))
+ (concat "#" target)))))
+ (concat host (gnus--string-truncate-left rest (- max (length host)))))))
(defun gnus-summary-browse-url (&optional external)
"Scan the current article body for links, and offer to browse them.
--
2.26.0
[-- Attachment #3: Type: text/plain, Size: 18 bytes --]
--
Štěpán
next prev parent reply other threads:[~2020-04-12 20:02 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-08 9:06 bug#39980: [PATCH] gnus-shorten-url: Improve and avoid args-out-of-range error Štěpán Němec
2020-03-14 11:41 ` Lars Ingebrigtsen
2020-03-14 16:34 ` Štěpán Němec
2020-03-14 18:03 ` Lars Ingebrigtsen
2020-03-14 18:12 ` Štěpán Němec
2020-03-14 18:15 ` Eli Zaretskii
2020-03-28 14:17 ` Štěpán Němec
2020-04-02 11:01 ` Lars Ingebrigtsen
2020-04-12 9:53 ` Štěpán Němec
2020-04-12 10:33 ` Eli Zaretskii
2020-04-12 10:49 ` Štěpán Němec
2020-04-12 11:05 ` Eli Zaretskii
2020-04-12 11:47 ` Štěpán Němec
2020-04-12 13:38 ` Eli Zaretskii
2020-04-12 14:13 ` Štěpán Němec
2020-04-12 14:35 ` Eli Zaretskii
2020-04-12 20:02 ` Štěpán Němec [this message]
2020-04-13 4:26 ` Eli Zaretskii
2020-04-13 10:31 ` Štěpán Němec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d08cbhh1.fsf@gmail.com \
--to=stepnem@gmail.com \
--cc=39980@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.