GNU bug report logs - #39980
[PATCH] gnus-shorten-url: Improve and avoid args-out-of-range error

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Štěpán Němec <stepnem@HIDDEN>; Keywords: patch; dated Sun, 8 Mar 2020 09:07:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 39980 <at> debbugs.gnu.org:


Received: (at 39980) by debbugs.gnu.org; 14 Mar 2020 16:34:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 14 12:34:36 2020
Received: from localhost ([127.0.0.1]:33865 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jD9kB-0004Ox-Nr
	for submit <at> debbugs.gnu.org; Sat, 14 Mar 2020 12:34:35 -0400
Received: from mail-lj1-f174.google.com ([209.85.208.174]:38707)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <stepnem@HIDDEN>) id 1jD9k9-0004Ok-PR
 for 39980 <at> debbugs.gnu.org; Sat, 14 Mar 2020 12:34:34 -0400
Received: by mail-lj1-f174.google.com with SMTP id w1so13987626ljh.5
 for <39980 <at> debbugs.gnu.org>; Sat, 14 Mar 2020 09:34:33 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:cc:subject:in-reply-to:references:user-agent:date
 :message-id:mime-version:content-transfer-encoding;
 bh=SAqdCxT/0MxZRAleo+N+la2K3/l9RMT5Rmvbvph8KYY=;
 b=PI9eSXekaU4a8HYmckycJoqA4+HJNrD7zBWhFKCYqjiF2hAft7oRzEDqtQ+pAuJ98R
 RNTSdL2kzCBupXfOBdLoOkxskZl1vkQCkAYhOsupXMKwMXqCXE26OHsk4BBywwtK4I8E
 YoeFlpqoop5ZdWavo+VjHSQEODmZzAajehc6F0iZ+62DcO/YlLMARJgprHJyX3wFPpEe
 9QH9gwJNgdjqDbfvcnvIpCnjXjRNEj3Bb8maTPiA5A/NQALRZ1mPWBdXb4SBIoiHov1m
 +2ed5YzFc4v/BFQOyb7E74UOXtKIMwRd0Lj13cnBTji0QTbCPreaPrDNPyELKxw4UMMM
 8UVw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:cc:subject:in-reply-to:references
 :user-agent:date:message-id:mime-version:content-transfer-encoding;
 bh=SAqdCxT/0MxZRAleo+N+la2K3/l9RMT5Rmvbvph8KYY=;
 b=DSQL7TbPIXcTVfVt74RTdsEP2wu9YXj+jJxHjupI2fmdzj0E9whIG9Uo0f9jNPibkE
 4JfZpSZIFhRLAo1Rs9+hVPE+GkUezZ/F4mTk8XthcisoZLEYSZCjP+093o/oLdjslXWo
 cZQAySpjwy/vgXtCtoh0XtSpc78s1Sx3nkXrBTHEoi/fveAlXtH8O3P4BQ1mzG1CM+Av
 4ZNtgTbzGd1f25TJorYk92ctA7tfkNCvEtwW8yS2WlwrzsSTzUBDGnbroWB7xVFjT4NO
 e0Z+M0uZ7ueXY/3ioCt0OfE+vDD1kNg7xTFFM6R/QgiuyllG9qdCb5HHBzyeads0tCbL
 RZXQ==
X-Gm-Message-State: ANhLgQ1GgSjBrsbYMRyA8xko5FxnDj26TL48Pb2ETb5GSm7pqeVfMRpC
 uIRiyCA05Y8ABsiJkI8+i2Y=
X-Google-Smtp-Source: ADFU+vukzzkAOG0QRxpIhmrZsxjQeXiUrat/HTovBPGQVyG14DgbWbfTeRh/WmiE0Ueq27IG6O887A==
X-Received: by 2002:a2e:3a11:: with SMTP id h17mr4073368lja.110.1584203667709; 
 Sat, 14 Mar 2020 09:34:27 -0700 (PDT)
Received: from localhost ([185.112.167.59])
 by smtp.gmail.com with ESMTPSA id h14sm1055105lfc.24.2020.03.14.09.34.26
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sat, 14 Mar 2020 09:34:26 -0700 (PDT)
From: =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= <stepnem@HIDDEN>
To: Lars Ingebrigtsen <larsi@HIDDEN>
Subject: Re: bug#39980: [PATCH] gnus-shorten-url: Improve and avoid
 args-out-of-range error
In-Reply-To: <87pndf17v5.fsf@HIDDEN> (Lars Ingebrigtsen's message of "Sat,
 14 Mar 2020 12:41:34 +0100")
References: <20200308090630.41238-1-stepnem@HIDDEN>
 <87pndf17v5.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
Date: Sat, 14 Mar 2020 17:34:46 +0100
Message-ID: <87zhcinbdl.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 3.6 (+++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  On Sat, 14 Mar 2020 12:41:34 +0100 Lars Ingebrigtsen wrote:
 > Looks like a good fix to me, but is there a reason this is a defsubst >
 instead of a defun? > > +(defsubst string-truncate-left (string length) 
 Content analysis details:   (3.6 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
 3.6 RCVD_IN_SBL_CSS        RBL: Received via a relay in Spamhaus SBL-CSS
 [185.112.167.59 listed in zen.spamhaus.org]
 0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
 0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
 provider (stepnem[at]gmail.com)
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
 no trust [209.85.208.174 listed in list.dnswl.org]
 -0.0 RCVD_IN_MSPIKE_H2      RBL: Average reputation (+2)
 [209.85.208.174 listed in wl.mailspike.net]
X-Debbugs-Envelope-To: 39980
Cc: 39980 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 2.6 (++)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 
 Content preview:  On Sat, 14 Mar 2020 12:41:34 +0100 Lars Ingebrigtsen wrote:
    > Looks like a good fix to me, but is there a reason this is a defsubst >
    instead of a defun? > > +(defsubst string-truncate-left (string length) 
 
 Content analysis details:   (2.6 points, 10.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 RCVD_IN_MSPIKE_H2      RBL: Average reputation (+2)
                             [209.85.208.174 listed in wl.mailspike.net]
 -0.0 RCVD_IN_DNSWL_NONE     RBL: Sender listed at https://www.dnswl.org/,
                              no trust
                             [209.85.208.174 listed in list.dnswl.org]
  3.6 RCVD_IN_SBL_CSS        RBL: Received via a relay in Spamhaus SBL-CSS
                             [185.112.167.59 listed in zen.spamhaus.org]
 -0.0 SPF_PASS               SPF: sender matches SPF record
  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record
  0.0 FREEMAIL_FROM          Sender email is commonly abused enduser mail
                             provider (stepnem[at]gmail.com)
 -1.0 MAILING_LIST_MULTI     Multiple indicators imply a widely-seen list
                             manager

On Sat, 14 Mar 2020 12:41:34 +0100
Lars Ingebrigtsen wrote:

> Looks like a good fix to me, but is there a reason this is a defsubst
> instead of a defun?
>
> +(defsubst string-truncate-left (string length)

subr-x is supposed to be loaded at compile time (see the file's
Commentary), so, with the single exception of `replace-region-contents'
(I wonder how that happened...), everything in there is either a macro
or a defsubst.

I would personally welcome lifting that limitation (again, what about
that one exception which needs to load it at run time, anyway?) as IME
it causes confusion with some users and package developers, too, but I'm
not sure that's an option.

--=20
=C5=A0t=C4=9Bp=C3=A1n




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#39980; Package emacs. Full text available.

Message received at 39980 <at> debbugs.gnu.org:


Received: (at 39980) by debbugs.gnu.org; 14 Mar 2020 11:41:44 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Mar 14 07:41:44 2020
Received: from localhost ([127.0.0.1]:60666 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jD5Am-0008IW-8W
	for submit <at> debbugs.gnu.org; Sat, 14 Mar 2020 07:41:44 -0400
Received: from quimby.gnus.org ([95.216.78.240]:56224)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1jD5Al-0008IJ-38
 for 39980 <at> debbugs.gnu.org; Sat, 14 Mar 2020 07:41:43 -0400
Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie)
 by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.92) (envelope-from <larsi@HIDDEN>)
 id 1jD5Ad-0001Lt-8F; Sat, 14 Mar 2020 12:41:37 +0100
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: =?utf-8?B?xaB0xJtww6FuIE7Em21lYw==?= <stepnem@HIDDEN>
Subject: Re: bug#39980: [PATCH] gnus-shorten-url: Improve and avoid
 args-out-of-range error
References: <20200308090630.41238-1-stepnem@HIDDEN>
Date: Sat, 14 Mar 2020 12:41:34 +0100
In-Reply-To: <20200308090630.41238-1-stepnem@HIDDEN> (=?utf-8?B?IsWg?=
 =?utf-8?B?dMSbcMOhbiBOxJttZWMiJ3M=?=
 message of "Sun, 8 Mar 2020 10:06:30 +0100")
Message-ID: <87pndf17v5.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 
 Content preview:  Štěpán Němec <stepnem@HIDDEN> writes: > '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 [...] 
 
 Content analysis details:   (-2.9 points, 5.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
  0.0 URIBL_BLOCKED          ADMINISTRATOR NOTICE: The query to URIBL was
                             blocked.  See
                             http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block
                              for more information.
                             [URIs: ingebrigtsen.no]
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
                             [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 39980
Cc: 39980 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

=C5=A0t=C4=9Bp=C3=A1n N=C4=9Bmec <stepnem@HIDDEN> writes:

> '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" 4=
0)
>   ;; =3D> 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.

Looks like a good fix to me, but is there a reason this is a defsubst
instead of a defun?

+(defsubst string-truncate-left (string length)

--=20
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#39980; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 8 Mar 2020 09:06:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Mar 08 05:06:22 2020
Received: from localhost ([127.0.0.1]:47887 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1jArt7-0000tf-N9
	for submit <at> debbugs.gnu.org; Sun, 08 Mar 2020 05:06:22 -0400
Received: from lists.gnu.org ([209.51.188.17]:59034)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <stepnem@HIDDEN>) id 1jArt6-0000tW-9V
 for submit <at> debbugs.gnu.org; Sun, 08 Mar 2020 05:06:20 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10]:54039)
 by lists.gnu.org with esmtp (Exim 4.90_1)
 (envelope-from <stepnem@HIDDEN>) id 1jArt4-0008F3-L0
 for bug-gnu-emacs@HIDDEN; Sun, 08 Mar 2020 05:06:20 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM
 autolearn=disabled version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <stepnem@HIDDEN>) id 1jArt3-0006J7-2R
 for bug-gnu-emacs@HIDDEN; Sun, 08 Mar 2020 05:06:18 -0400
Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:34882)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
 (Exim 4.71) (envelope-from <stepnem@HIDDEN>) id 1jArt2-0006Ho-PN
 for bug-gnu-emacs@HIDDEN; Sun, 08 Mar 2020 05:06:17 -0400
Received: by mail-lf1-x131.google.com with SMTP id z9so5211834lfa.2
 for <bug-gnu-emacs@HIDDEN>; Sun, 08 Mar 2020 01:06:16 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
 h=from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=QBAg1mBDZdRKohkxr6fHtzCzENWNWvydgjdbeAEQAmw=;
 b=npWb6I0ShyNRti3yz8cfXQycSITs4E8pJK+H14SI31INCPzfPJaL2Xzu2fhROmFzIY
 vpGYI6hO8WFbU6M8adLrM5aP9F3ZHr1VlAXcVgrzZ4eLeLcG6QvWSD9091FuUTDHEXQn
 o+hLyB8gEke4HuaibpzhEaIG0SI92CKzP6gE9rQWBJuK7HD4n/AMnDwuUkzGEwQd6o8R
 iiMa76whfUaWR4HylzwWcYY5AS6JBzFsBsfLMWGtucTlp+/sYOaYRdHpECivBKslQAUs
 v+9qYNv/7fMmZwg2WixUwk4RIgOUiTE8lgcVe91p1QR2vYgc0QYwM8ndeE/iDorPUTjZ
 UdFQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20161025;
 h=x-gm-message-state:from:to:subject:date:message-id:mime-version
 :content-transfer-encoding;
 bh=QBAg1mBDZdRKohkxr6fHtzCzENWNWvydgjdbeAEQAmw=;
 b=SBsPlksSlx2CgSM5qzmXyRH9IdlMM1KiCu8bnanZABeH5uOl4sJ2pDRsVevHIMbpCL
 dAnOgZSkxUKqSrydgbx+RuWJd3CZztFyo1tcU+YUIaRPfYMMnLeeR5wW1a76zkpx9+MQ
 W9D3Re4uRg+bllsNiW24QTPl3uAuhgGFyfLfJhwFMEtDw8BgG96fVnyFgVGsZdxFsCm5
 W8/sozfTntHfbgfDr6mH6nMct7yuttPMYy3CWvKUC4nYtTIZ+ZVa9nsBeisX/i1GOhNf
 tg0ZeewYVaD3z24aMDYVOTzNgIzrbI9uGk6IIy5q48I1v+LxBJmNdxuio1nm2zxosS9n
 v1tQ==
X-Gm-Message-State: ANhLgQ2mq/XJjcR5uYJElWNcY45M+UwGsPrmS/Y87O8ZEQW5EKVxZHgF
 UkkNd96LpmPVNovTtEw7bYtuSHQV
X-Google-Smtp-Source: ADFU+vvHihZ4CkDX2CUP/ldHo5OWDj16yuWMgBZpY6BUC0pexC8/fjPq2SWPyYDOWh9kgcNEwXU89A==
X-Received: by 2002:ac2:43c8:: with SMTP id u8mr6395043lfl.180.1583658374350; 
 Sun, 08 Mar 2020 01:06:14 -0800 (PST)
Received: from localhost ([185.112.167.59])
 by smtp.gmail.com with ESMTPSA id s16sm10281088ljs.65.2020.03.08.01.06.13
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 08 Mar 2020 01:06:13 -0800 (PST)
From: =?UTF-8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= <stepnem@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] gnus-shorten-url: Improve and avoid args-out-of-range error
Date: Sun,  8 Mar 2020 10:06:30 +0100
Message-Id: <20200308090630.41238-1-stepnem@HIDDEN>
X-Mailer: git-send-email 2.25.1
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-detected-operating-system: by eggs.gnu.org: Genre and OS details not
 recognized.
X-Received-From: 2a00:1450:4864:20::131
X-Spam-Score: 0.3 (/)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.7 (/)

'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.

* lisp/vc/ediff-init.el
(ediff-truncate-string-left): Rename to 'string-truncate-left'.
* lisp/emacs-lisp/subr-x.el (string-truncate-left): Move here.
* lisp/vc/ediff-mult.el (ediff-meta-insert-file-info1) (ediff-draw-dir-diffs):
'ediff-draw-dir-diffs' renamed to 'string-truncate-left'.
* lisp/gnus/gnus-sum.el (gnus-shorten-url): Fix args-out-of-range
error, don't drop #fragments, use 'string-truncate-left'.
---
 lisp/emacs-lisp/subr-x.el |  8 ++++++++
 lisp/gnus/gnus-sum.el     | 14 +++++++-------
 lisp/vc/ediff-init.el     | 10 ----------
 lisp/vc/ediff-mult.el     | 10 ++++++----
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index 044c9aada0..baf20131cc 100644
--- a/lisp/emacs-lisp/subr-x.el
+++ b/lisp/emacs-lisp/subr-x.el
@@ -236,6 +236,14 @@ string-trim
 TRIM-LEFT and TRIM-RIGHT default to \"[ \\t\\n\\r]+\"."
   (string-trim-left (string-trim-right string trim-right) trim-left))
 
+(defsubst 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
diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el
index a47e657623..6f367692dd 100644
--- a/lisp/gnus/gnus-sum.el
+++ b/lisp/gnus/gnus-sum.el
@@ -9494,15 +9494,15 @@ gnus-collect-urls
     (delete-dups urls)))
 
 (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 (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.
diff --git a/lisp/vc/ediff-init.el b/lisp/vc/ediff-init.el
index cbd8c0d322..c7498064dc 100644
--- a/lisp/vc/ediff-init.el
+++ b/lisp/vc/ediff-init.el
@@ -1524,16 +1524,6 @@ ediff-strip-last-dir
 	(setq dir (substring dir 0 pos)))
     (ediff-abbreviate-file-name (file-name-directory dir))))
 
-(defun ediff-truncate-string-left (str newlen)
-  ;; leave space for ... on the left
-  (let ((len (length str))
-	substr)
-    (if (<= len newlen)
-	str
-      (setq newlen (max 0 (- newlen 3)))
-      (setq substr (substring str (max 0 (- len 1 newlen))))
-      (concat "..." substr))))
-
 (defsubst ediff-nonempty-string-p (string)
   (and (stringp string) (not (string= string ""))))
 
diff --git a/lisp/vc/ediff-mult.el b/lisp/vc/ediff-mult.el
index fee87e8352..5dcb42eb64 100644
--- a/lisp/vc/ediff-mult.el
+++ b/lisp/vc/ediff-mult.el
@@ -113,6 +113,8 @@ ediff-mult
 (require 'ediff-wind)
 (require 'ediff-util)
 
+(eval-when-compile
+  (require 'subr-x))                    ; string-truncate-left
 
 ;; meta-buffer
 (ediff-defvar-local ediff-meta-buffer nil "")
@@ -1172,7 +1174,7 @@ ediff-meta-insert-file-info1
 	  ;; abbreviate the file name, if file exists
 	  (if (and (not (stringp fname)) (< file-size -1))
 	      "-------"		; file doesn't exist
-	    (ediff-truncate-string-left
+	    (string-truncate-left
 	     (ediff-abbreviate-file-name fname)
 	     max-filename-width)))))))
 
@@ -1266,7 +1268,7 @@ ediff-draw-dir-diffs
 	(if (= (mod membership-code ediff-membership-code1) 0) ; dir1
 	    (let ((beg (point)))
 	      (insert (format "%-27s"
-			      (ediff-truncate-string-left
+			      (string-truncate-left
 			       (ediff-abbreviate-file-name
 				(if (file-directory-p (concat dir1 file))
 				    (file-name-as-directory file)
@@ -1281,7 +1283,7 @@ ediff-draw-dir-diffs
 	(if (= (mod membership-code ediff-membership-code2) 0) ; dir2
 	    (let ((beg (point)))
 	      (insert (format "%-26s"
-			      (ediff-truncate-string-left
+			      (string-truncate-left
 			       (ediff-abbreviate-file-name
 				(if (file-directory-p (concat dir2 file))
 				    (file-name-as-directory file)
@@ -1295,7 +1297,7 @@ ediff-draw-dir-diffs
 	    (if (= (mod membership-code ediff-membership-code3) 0) ; dir3
 		(let ((beg (point)))
 		  (insert (format " %-25s"
-				  (ediff-truncate-string-left
+				  (string-truncate-left
 				   (ediff-abbreviate-file-name
 				    (if (file-directory-p (concat dir3 file))
 					(file-name-as-directory file)
-- 
2.25.1





Acknowledgement sent to Štěpán Němec <stepnem@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#39980; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sat, 14 Mar 2020 16:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.