GNU bug report logs - #22460
'y' command doesn't allow a comment after it one the same line

Previous Next

Package: sed;

Reported by: Thorsten Heymann <hek2mgl <at> metashock.net>

Date: Mon, 25 Jan 2016 01:57:01 UTC

Severity: normal

Tags: fixed

Done: Assaf Gordon <assafgordon <at> gmail.com>

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 22460 in the body.
You can then email your comments to 22460 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-sed <at> gnu.org:
bug#22460; Package sed. (Mon, 25 Jan 2016 01:57:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Thorsten Heymann <hek2mgl <at> metashock.net>:
New bug report received and forwarded. Copy sent to bug-sed <at> gnu.org. (Mon, 25 Jan 2016 01:57:01 GMT) Full text and rfc822 format available.

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

From: Thorsten Heymann <hek2mgl <at> metashock.net>
To: bug-sed <at> gnu.org
Subject: 'y' command doesn't allow a comment after it one the same line
Date: Mon, 25 Jan 2016 02:28:22 +0100
Unlike other commands, the current implementation of the 'y' command does not allow a comment on the same line if the command is not "terminated" by a ';'

For example (the comments are part of the program):

    s/1/a/g    # Substitute 1's by a's
    x          # Swapping hold and pattern buffer
    1d         # Deleting the first line
    ...

works, but

    y/1/a/     # Substitute 1's by a's

produces:

    sed: -e expression #1, char 8: extra characters after command

This patch fixes this.

Greets,
Thorsten
---
 sed/compile.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sed/compile.c b/sed/compile.c
index 270caaf..442aeb5 100644
--- a/sed/compile.c
+++ b/sed/compile.c
@@ -1329,7 +1329,10 @@ compile_program(struct vector *vector)
                 cur_cmd->x.translate = translate;
               }
 
-            if ((ch = in_nonblank()) != EOF && ch != '\n' && ch != ';')
+            ch = in_nonblank();
+            if (ch == CLOSE_BRACE || ch == '#')
+              savchar(ch);
+            else if (ch != EOF && ch != '\n' && ch != ';')
               bad_prog(_(EXCESS_JUNK));
 
             free_buffer(b);
-- 
2.4.10





Information forwarded to bug-sed <at> gnu.org:
bug#22460; Package sed. (Fri, 27 Jan 2017 03:06:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Thorsten Heymann <hek2mgl <at> metashock.net>
Cc: 22460 <at> debbugs.gnu.org
Subject: Re: bug#22460: 'y' command doesn't allow a comment after it one the
 same line
Date: Fri, 27 Jan 2017 03:04:27 +0000
[Message part 1 (text/plain, inline)]
Hello Thorsten,

Sorry for the delayed response.

On Mon, Jan 25, 2016 at 02:28:22AM +0100, Thorsten Heymann wrote:
>Unlike other commands, the current implementation of the 'y' command does
>not allow a comment on the same line if the command is not
>"terminated" by a ';'

That is indeed a bug, and a rather old one.

Your suggested fix is correct, but I thought that instead of
duplicating the same few lines, it might be better to extract
the code to a new function.

The attached patch does that and adds a corresponding unit test.

Comments welcomed,
- assaf


[0001-sed-allow-comments-braces-after-y.patch (text/x-diff, attachment)]

Information forwarded to bug-sed <at> gnu.org:
bug#22460; Package sed. (Sun, 19 Mar 2017 03:36:01 GMT) Full text and rfc822 format available.

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

From: Jim Meyering <jim <at> meyering.net>
To: Assaf Gordon <assafgordon <at> gmail.com>
Cc: 22460 <at> debbugs.gnu.org, Thorsten Heymann <hek2mgl <at> metashock.net>
Subject: Re: bug#22460: 'y' command doesn't allow a comment after it one the
 same line
Date: Sat, 18 Mar 2017 20:34:48 -0700
On Thu, Jan 26, 2017 at 7:04 PM, Assaf Gordon <assafgordon <at> gmail.com> wrote:
> Hello Thorsten,
>
> Sorry for the delayed response.
>
> On Mon, Jan 25, 2016 at 02:28:22AM +0100, Thorsten Heymann wrote:
>>
>> Unlike other commands, the current implementation of the 'y' command does
>> not allow a comment on the same line if the command is not
>> "terminated" by a ';'
>
>
> That is indeed a bug, and a rather old one.
>
> Your suggested fix is correct, but I thought that instead of
> duplicating the same few lines, it might be better to extract
> the code to a new function.
>
> The attached patch does that and adds a corresponding unit test.

Thank you, Thorsten, for the report and patch.

Hi Assaf,
Thanks a lot for improving it and adding tests.

Would you please separate the factoring-out of your new function and
the bug fix into two commits?
Maybe even putting the tests in a third.

A nit in the commit log, now that 4.4 is out, it should say sed-4.4,
not 4.3, of course.




Information forwarded to bug-sed <at> gnu.org:
bug#22460; Package sed. (Wed, 22 Mar 2017 02:55:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 22460 <at> debbugs.gnu.org, Thorsten Heymann <hek2mgl <at> metashock.net>
Subject: Re: bug#22460: 'y' command doesn't allow a comment after it one the
 same line
Date: Tue, 21 Mar 2017 22:54:05 -0400
[Message part 1 (text/plain, inline)]
Hello,

> On Mar 18, 2017, at 23:34, Jim Meyering <jim <at> meyering.net> wrote:
> 
> Would you please separate the factoring-out of your new function and
> the bug fix into two commits?
> Maybe even putting the tests in a third.

Thanks for the review.

Please see attached 3 patches, let me know if that's the right direction.

-assaf


[bug22460-2017-03-21.patch (application/octet-stream, attachment)]

Information forwarded to bug-sed <at> gnu.org:
bug#22460; Package sed. (Wed, 22 Mar 2017 05:01:01 GMT) Full text and rfc822 format available.

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

From: Jim Meyering <jim <at> meyering.net>
To: Assaf Gordon <assafgordon <at> gmail.com>
Cc: 22460 <at> debbugs.gnu.org, Thorsten Heymann <hek2mgl <at> metashock.net>
Subject: Re: bug#22460: 'y' command doesn't allow a comment after it one the
 same line
Date: Tue, 21 Mar 2017 22:00:31 -0700
On Tue, Mar 21, 2017 at 7:54 PM, Assaf Gordon <assafgordon <at> gmail.com> wrote:
> Hello,
>
>> On Mar 18, 2017, at 23:34, Jim Meyering <jim <at> meyering.net> wrote:
>>
>> Would you please separate the factoring-out of your new function and
>> the bug fix into two commits?
>> Maybe even putting the tests in a third.
>
> Thanks for the review.
>
> Please see attached 3 patches, let me know if that's the right direction.

Perfect. I spotted only one nit: in the log of the middle patch,
s/savinh/saving/
Thanks!




Information forwarded to bug-sed <at> gnu.org:
bug#22460; Package sed. (Fri, 24 Mar 2017 04:25:02 GMT) Full text and rfc822 format available.

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

From: Assaf Gordon <assafgordon <at> gmail.com>
To: Jim Meyering <jim <at> meyering.net>
Cc: 22460 <at> debbugs.gnu.org, Thorsten Heymann <hek2mgl <at> metashock.net>
Subject: Re: bug#22460: 'y' command doesn't allow a comment after it one the
 same line
Date: Fri, 24 Mar 2017 00:24:42 -0400
tags 22460 fixed
close 22460
stop

Pushed here:

sed: allow comments, braces after y///
 https://git.savannah.gnu.org/cgit/sed.git/commit/?id=cf8eb6cb3

sed: refactor end-of-line parsing
 https://git.savannah.gnu.org/cgit/sed.git/commit/?id=9b26a0651

tests: test comments, braces after commands
 https://git.savannah.gnu.org/cgit/sed.git/commit/?id=156e6be99f


regards,
 - assaf




Added tag(s) fixed. Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 24 Mar 2017 04:25:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 22460 <at> debbugs.gnu.org and Thorsten Heymann <hek2mgl <at> metashock.net> Request was from Assaf Gordon <assafgordon <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 24 Mar 2017 04:25:02 GMT) Full text and rfc822 format available.

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

This bug report was last modified 8 years and 98 days ago.

Previous Next


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