emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#21253: closed (sed escape bug)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#21253: closed (sed escape bug)
Date: Thu, 16 Feb 2017 22:54:01 +0000

Your message dated Thu, 16 Feb 2017 22:52:32 +0000
with message-id <address@hidden>
and subject line RE: sed escape bug
has caused the debbugs.gnu.org bug report #21253,
regarding sed escape bug
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
21253: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=21253
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: sed escape bug Date: Thu, 13 Aug 2015 08:24:33 -0400
The escape '\c\' fails at the end of a regex.

~$ echo a | sed -e 's/a/\c\/' | hexdump -c
sed: -e _expression_ #1, char 8: unterminated `s' command
~$ echo a | sed -e 's/a/\c\b/' | hexdump -c
0000000 034   b  \n
0000003
~$ sed --version
sed (GNU sed) 4.2.2
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Jay Fenlason, Tom Lord, Ken Pizzini,
and Paolo Bonzini.
GNU sed home page: <http://www.gnu.org/software/sed/>.
General help using GNU software: <http://www.gnu.org/gethelp/>.
E-mail bug reports to: <address@hidden>.
Be sure to include the word ``sed'' somewhere in the ``Subject:'' field.


--- End Message ---
--- Begin Message --- Subject: RE: sed escape bug Date: Thu, 16 Feb 2017 22:52:32 +0000 User-agent: Mutt/1.5.23 (2014-03-12)
Hello,

Sorry for the delayed response.


Jacob Young <amazingjacob <at> gmail.com> wrote:
The escape '\c\' fails at the end of a regex.

~$ echo a | sed -e 's/a/\c\/' | hexdump -c
sed: -e expression #1, char 8: unterminated `s' command
~$ echo a | sed -e 's/a/\c\b/' | hexdump -c
0000000 034   b  \n
0000003
~$ sed --version
sed (GNU sed) 4.2.2

This is an interesting case:
It's a bug in older sed-4.2.2, but the fix is perhaps not your expected behaviour of allowing '/' after '\c\'.

A single backslash after '\c' was ambigious in sed-4.2.2:
Should it be parsed as the option to '\c' (e.g. '\c\' is like '\cA'),
or should it be parsed like other back-slashes, where it removes
the special meaning of the following character (e.g. 's/x/\//' replaces
an 'x' with a '/' ).

The previous behaviour lead to inconsistencies, exactly
as you've encountered. Compare:

   # '\t' means TAB, backslash affects the character that follows:
   $ echo x | sed-4.2.2 's/x/\t/' | hexdump -c
   0000000  \t  \n
   0000002

   # but here the '\c\' is taken as one item, and 't' is parsed by itself:
   $ echo x | sed-4.2.2  's/x/\c\t/' | hexdump -c
   0000000 034   t  \n
   0000003

   # yet '/' immediately after '\c\' was rejected:
   $ echo x | sed-4.2.2 -e 's/x/\c\/' | hexdump -c
   sed: -e expression #1, char 8: unterminated `s' command

Commit v4.2.2-99-g156e099 [1] fixed this behaviour.
To use backslash as control character, TWO backslashes are required -
just like using a literal backslash anywhere else:

   ## Two backslashes are needed for CTRL-\
   $ echo x | sed-4.4 's/x/\c\\/' | hexdump -c
   0000000 034  \n
   0000002

   ## A single backslash is not enough:
   $ echo x | sed-4.4 's/x/\c\/' | hexdump -c
   sed: -e expression #1, char 8: unterminated `s' command


   ## Ambigious usage is rejected:
   $ echo x | sed-4.4 's/x/\c\t/' | hexdump -c
   sed: -e expression #1, char 9: recursive escaping after \c not allowed

This behaviour was introduced in sed-4.3.

As such I'm closing this bug, but discussion can continue
by replying to this thread.

regards,
- assaf


[1] https://git.savannah.gnu.org/cgit/sed.git/commit/?id=156e0998





--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]