GNU bug report logs - #69822
[PATCH] format-spec pads when it should only truncate

Previous Next

Package: emacs;

Reported by: Adam Porter <adam <at> alphapapa.net>

Date: Sat, 16 Mar 2024 02:30:02 UTC

Severity: normal

Tags: patch

Done: Adam Porter <adam <at> alphapapa.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 69822 in the body.
You can then email your comments to 69822 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sat, 16 Mar 2024 02:30:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Adam Porter <adam <at> alphapapa.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 16 Mar 2024 02:30:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] format-spec pads when it should only truncate
Date: Fri, 15 Mar 2024 21:28:15 -0500
[Message part 1 (text/plain, inline)]
Hi,

Please see the attached patch which fixes a bug in `format-spec': that a 
format spec like "%>15t", which is intended to limit the width of a 
string to 15 characters, would also pad a string less than that length 
to be that length.

Please note the test case which the patch essentially disables: it calls 
one of the intermediate functions with arguments which I'm not sure it 
would be called with in real usage.  I added two test cases to cover the 
behavior which the patch is intended to fix, and after editing the 
`format-spec--do-flags' to pass the new cases, only that one case 
failed; so, since I'm not sure whether it indicates an actual bug, I 
disabled it.

Perhaps there exists a real-world scenario to which that test would 
apply, but such is not encoded as an end-to-end test of `format-spec' 
with a spec string, so it's hard to say.

In other words, this patch fixes a real bug and adds test cases for it. 
It also causes an existing case to fail, but since I'm not sure whether 
that represents a real bug, that case is now disabled.

All other tests in the file still pass.

Thanks,
Adam
[0001-format-spec-do-flags-Don-t-pad-when-just-truncating.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sat, 16 Mar 2024 10:24:02 GMT) Full text and rfc822 format available.

Message #8 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Porter <adam <at> alphapapa.net>
Cc: 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sat, 16 Mar 2024 12:22:26 +0200
> Date: Fri, 15 Mar 2024 21:28:15 -0500
> From: Adam Porter <adam <at> alphapapa.net>
> 
> Please see the attached patch which fixes a bug in `format-spec': that a 
> format spec like "%>15t", which is intended to limit the width of a 
> string to 15 characters, would also pad a string less than that length 
> to be that length.

I don't understand why you consider it a bug.  According to the doc
string (see below), this:

  (format-spec "%>15t" '((?t . "0123456789")))

should behave the same as this:

  (format "%15s" "0123456789")

And in my testing, it does: both produce "     0123456789".

So I don't think I agree that there's a bug here to begin with.  The
doc string of format-spec says:

  The width and truncation modifiers behave like the corresponding
  ones in ‘format’ when applied to %s.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sat, 16 Mar 2024 10:37:02 GMT) Full text and rfc822 format available.

Message #11 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <basil <at> contovou.net>
To: Adam Porter <adam <at> alphapapa.net>
Cc: 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sat, 16 Mar 2024 11:35:16 +0100
Adam Porter [2024-03-15 21:28 -0500] wrote:

> Please see the attached patch which fixes a bug in `format-spec': that a format
> spec like "%>15t", which is intended to limit the width of a string to 15
> characters, would also pad a string less than that length to be that length.

In this format string, 15 is the 'width' (which controls padding), not
the 'precision' (which controls truncation).

To truncate beyond 15 without padding, specify a precision instead of a
width: "%>.15t".

So I'm not sure there's a bug here, or at least not the one you
describe.

What's not clear in the documentation is what happens when one specifies
< or > without an explicit precision, as in the example you give.  I'm
guessing this was the source of confusion here.  But I think this can be
addressed as a docfix.  Or am I missing something?

Thanks,
-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sun, 17 Mar 2024 04:13:01 GMT) Full text and rfc822 format available.

Message #14 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: "Basil L. Contovounesios" <basil <at> contovou.net>, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sat, 16 Mar 2024 23:12:16 -0500
Hi Eli, Basil,

On 3/16/24 05:22, Eli Zaretskii wrote:

> I don't understand why you consider it a bug.  According to the doc 
> string (see below)...
> 
> So I don't think I agree that there's a bug here to begin with.  The 
> doc string of format-spec says:
> 
> The width and truncation modifiers behave like the corresponding ones
> in ‘format’ when applied to %s.

Thanks, now I understand.

Should I close the bug, or do you think the docstring should be changed 
to help clarify this?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sun, 17 Mar 2024 06:25:02 GMT) Full text and rfc822 format available.

Message #17 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Adam Porter <adam <at> alphapapa.net>
Cc: basil <at> contovou.net, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sun, 17 Mar 2024 08:23:26 +0200
> Date: Sat, 16 Mar 2024 23:12:16 -0500
> Cc: 69822 <at> debbugs.gnu.org, "Basil L. Contovounesios" <basil <at> contovou.net>
> From: Adam Porter <adam <at> alphapapa.net>
> 
> Hi Eli, Basil,
> 
> On 3/16/24 05:22, Eli Zaretskii wrote:
> 
> > I don't understand why you consider it a bug.  According to the doc 
> > string (see below)...
> > 
> > So I don't think I agree that there's a bug here to begin with.  The 
> > doc string of format-spec says:
> > 
> > The width and truncation modifiers behave like the corresponding ones
> > in ‘format’ when applied to %s.
> 
> Thanks, now I understand.
> 
> Should I close the bug, or do you think the docstring should be changed 
> to help clarify this?

If there's something in the doc string that is unclear, please tell
what that is, and let's by all means try to find ways to clarify that.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Sun, 17 Mar 2024 12:13:01 GMT) Full text and rfc822 format available.

Message #20 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <basil <at> contovou.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Adam Porter <adam <at> alphapapa.net>, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sun, 17 Mar 2024 13:11:25 +0100
[Message part 1 (text/plain, inline)]
Eli Zaretskii [2024-03-17 08:23 +0200] wrote:

>> Date: Sat, 16 Mar 2024 23:12:16 -0500
>> Cc: 69822 <at> debbugs.gnu.org, "Basil L. Contovounesios" <basil <at> contovou.net>
>> From: Adam Porter <adam <at> alphapapa.net>
>> 
>> Hi Eli, Basil,
>> 
>> On 3/16/24 05:22, Eli Zaretskii wrote:
>> 
>> > I don't understand why you consider it a bug.  According to the doc 
>> > string (see below)...
>> > 
>> > So I don't think I agree that there's a bug here to begin with.  The 
>> > doc string of format-spec says:
>> > 
>> > The width and truncation modifiers behave like the corresponding ones
>> > in ‘format’ when applied to %s.
>> 
>> Thanks, now I understand.
>> 
>> Should I close the bug, or do you think the docstring should be changed 
>> to help clarify this?
>
> If there's something in the doc string that is unclear, please tell
> what that is, and let's by all means try to find ways to clarify that.

How about this for now?

[0001-Clarify-description-of-format-spec-truncation.patch (text/x-diff, attachment)]
[Message part 3 (text/plain, inline)]
I don't know why I added 'and precision' to the description of '<' but
not '>' in:

  Fix and extend format-spec (bug#41758)
  0185d76e742 2020-06-18 12:46:21 +0100
  https://git.sv.gnu.org/cgit/emacs.git/commit/?id=0185d76e742

Thanks,
-- 
Basil

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Mon, 18 Mar 2024 01:17:02 GMT) Full text and rfc822 format available.

Message #23 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: "Basil L. Contovounesios" <basil <at> contovou.net>,
 Eli Zaretskii <eliz <at> gnu.org>
Cc: 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sun, 17 Mar 2024 20:16:14 -0500
Hi Basil, Eli,

On 3/17/24 07:11, Basil L. Contovounesios wrote:

>>> Should I close the bug, or do you think the docstring should be changed
>>> to help clarify this?
>>
>> If there's something in the doc string that is unclear, please tell
>> what that is, and let's by all means try to find ways to clarify that.
> 
> How about this for now?

Thanks, I think that will be helpful.

--Adam




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Thu, 21 Mar 2024 09:54:02 GMT) Full text and rfc822 format available.

Message #26 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <basil <at> contovou.net>
To: Adam Porter <adam <at> alphapapa.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Thu, 21 Mar 2024 10:52:57 +0100
Adam Porter [2024-03-17 20:16 -0500] wrote:
> On 3/17/24 07:11, Basil L. Contovounesios wrote:
>>>> Should I close the bug, or do you think the docstring should be changed
>>>> to help clarify this?
>>> If there's something in the doc string that is unclear, please tell
>>> what that is, and let's by all means try to find ways to clarify that.
>> How about this for now?
> Thanks, I think that will be helpful.

Pushed to emacs-29:

Clarify description of format-spec truncation
689f04a2ddf 2024-03-21 10:43:17 +0100
https://git.sv.gnu.org/cgit/emacs.git/commit/?id=689f04a2ddf

Feel free to keep this open if you think there's more to be done here.
Or can the report be closed?

Thanks,
-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Thu, 21 Mar 2024 10:49:02 GMT) Full text and rfc822 format available.

Message #29 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: "Basil L. Contovounesios" <basil <at> contovou.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Thu, 21 Mar 2024 05:47:39 -0500
Hi Basil,

On 3/21/24 04:52, Basil L. Contovounesios wrote:
> Adam Porter [2024-03-17 20:16 -0500] wrote:
>> On 3/17/24 07:11, Basil L. Contovounesios wrote:
>>>>> Should I close the bug, or do you think the docstring should be changed
>>>>> to help clarify this?
>>>> If there's something in the doc string that is unclear, please tell
>>>> what that is, and let's by all means try to find ways to clarify that.
>>> How about this for now?
>> Thanks, I think that will be helpful.
> 
> Pushed to emacs-29:
> 
> Clarify description of format-spec truncation
> 689f04a2ddf 2024-03-21 10:43:17 +0100
> https://git.sv.gnu.org/cgit/emacs.git/commit/?id=689f04a2ddf
> 
> Feel free to keep this open if you think there's more to be done here.
> Or can the report be closed?

Thank you.  I'm happy for it to be closed.  (Can the reporter do that, 
or does it have to be a maintainer?  I can't remember, and the tracker's 
Web pages don't seem to say for certain.)

--Adam




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#69822; Package emacs. (Thu, 21 Mar 2024 11:05:01 GMT) Full text and rfc822 format available.

Message #32 received at 69822 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <basil <at> contovou.net>
To: Adam Porter <adam <at> alphapapa.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 69822 <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Thu, 21 Mar 2024 12:03:35 +0100
Adam Porter [2024-03-21 05:47 -0500] wrote:

> I'm happy for it to be closed.  (Can the reporter do that, or does
> it have to be a maintainer?  I can't remember, and the tracker's Web pages don't
> seem to say for certain.)

Anyone can close it.  The easiest way is to change the To/Cc address
from 69822 <at> debbugs.gnu.org to 69822-done <at> debbugs.gnu.org.

[Details are in the file admin/notes/bugtracker.]

Alternatively you can email or Bcc control <at> debbugs.gnu.org and start
your message with Debbugs commands.  I tend to rely on the command
debbugs-gnu-make-control-message from the debbugs package.

HTH,
-- 
Basil




Reply sent to Adam Porter <adam <at> alphapapa.net>:
You have taken responsibility. (Sat, 23 Mar 2024 14:00:02 GMT) Full text and rfc822 format available.

Notification sent to Adam Porter <adam <at> alphapapa.net>:
bug acknowledged by developer. (Sat, 23 Mar 2024 14:00:02 GMT) Full text and rfc822 format available.

Message #37 received at 69822-done <at> debbugs.gnu.org (full text, mbox):

From: Adam Porter <adam <at> alphapapa.net>
To: "Basil L. Contovounesios" <basil <at> contovou.net>
Cc: 69822-done <at> debbugs.gnu.org
Subject: Re: bug#69822: [PATCH] format-spec pads when it should only truncate
Date: Sat, 23 Mar 2024 08:59:06 -0500
On 3/21/24 06:03, Basil L. Contovounesios wrote:
> Adam Porter [2024-03-21 05:47 -0500] wrote:
> 
>> I'm happy for it to be closed.  (Can the reporter do that, or does
>> it have to be a maintainer?  I can't remember, and the tracker's Web pages don't
>> seem to say for certain.)
> 
> Anyone can close it.  The easiest way is to change the To/Cc address
> from 69822 <at> debbugs.gnu.org to 69822-done <at> debbugs.gnu.org.

Thanks, Basil.  Closing...




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 21 Apr 2024 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 55 days ago.

Previous Next


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