From nobody@FreeBSD.org  Thu Oct 18 21:03:44 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id BC0A9406
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 18 Oct 2012 21:03:44 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id A215A8FC08
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 18 Oct 2012 21:03:44 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q9IL3iYM096386
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 18 Oct 2012 21:03:44 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q9IL3iAU096385;
	Thu, 18 Oct 2012 21:03:44 GMT
	(envelope-from nobody)
Message-Id: <201210182103.q9IL3iAU096385@red.freebsd.org>
Date: Thu, 18 Oct 2012 21:03:44 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: sed improperly deals with escape chars
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         172862
>Category:       bin
>Synopsis:       sed(1) improperly deals with escape chars
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 18 21:10:00 UTC 2012
>Closed-Date:    
>Last-Modified:  Thu Apr 17 04:31:49 UTC 2014
>Originator:     Garrett Cooper
>Release:        9.1-STABLE
>Organization:
EMC Isilon
>Environment:
FreeBSD bayonetta.local 9.1-PRERELEASE FreeBSD 9.1-PRERELEASE #0 r240836M: Sat Sep 22 12:30:11 PDT 2012     gcooper@bayonetta.local:/usr/obj/store/freebsd/stable/9/sys/BAYONETTA  amd64
>Description:
sed doesn't appear to be doing the right thing with escape chars (in this case '\t'); it's not properly reinterpreting '\t' as \011, but is instead interpreting it was 't':

$ echo "foot " | sed -e 's/[\\t ]*$//' | hexdump -C
00000000  66 6f 6f 0a                                       |foo.|
00000004
$ echo "foot " | sed -E -e 's/[\\t ]*$//' | hexdump -C
00000000  66 6f 6f 0a                                       |foo.|
00000004

GNU sed does do the right thing with escape chars (verified on Fedora 17):

# cat /etc/redhat-release
Fedora release 17 (Beefy Miracle)
# echo foot | sed -e 's/[\t ]*$//' | hexdump -C
00000000  66 6f 6f 74 0a                                    |foot.|
00000005
# echo "foot " | sed -e 's/[\t ]*$//' | hexdump -C
00000000  66 6f 6f 74 0a                                    |foot.|
00000005
>How-To-Repeat:
echo foot | sed -e 's/[\t ]*$//'
>Fix:


>Release-Note:
>Audit-Trail:

From: "John D. Hendrickson and Sara Darnell" <johnandsara2@cox.net>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/172862: sed improperly deals with escape chars
Date: Sat, 20 Oct 2012 20:37:25 -0400

 Hi.  This should be files as a Question not a Bug.  You need to investigate things before claiming 
 "bug".
 
 
  > $ echo "foot " | sed -e 's/[\\t ]*$//' | hexdump -C
 
 What I see is your using [] wrong.  '\t' doesn't go inside it for many WELL documented reasons.
 
 Furthermore sed mathes '\t' without [] so why bother filing a bug against [] ?
 
 '\t' has been around more years than your were born and probably sed too...
 
 anyhow.  "ediquitte" is you ask questions to users and file bugs about only if your very as 
 professor sure and also know how to fix it (pref. wtih code patch filed which absolutely CANNOT 
 cause past software to stop working).
 
 
 p.s.
 
 So, when you see a "majorly relied upon" unix tool doing "something stupid"
 it's very likely you have more learning and asking to do.
 
 1) you don't want people hacking sed to make it work your way it would break
     past software
 
 2) you don't want BSD-SED to have false bugs filed it will make BSD look worse
     than it is
 
 3)  since early stable versions of free bsd, bsd has accumulated
     way too many bugs and fixes and hardware compat changes - about
     a suspicious ammount - and still isn't as stable as it had been )
 
From: Garrett Cooper <yaneurabeya@gmail.com>
To: johnandsara2@cox.net
Cc: freebsd-gnats-submit@freebsd.org
Subject: Re: bin/172862: sed improperly deals with escape chars
Date: Sat, 20 Oct 2012 18:23:26 -0700

 On Sat, Oct 20, 2012 at 5:37 PM, John D. Hendrickson and Sara Darnell
 <johnandsara2@cox.net> wrote:
 
 ...
 
 > What I see is your using [] wrong.  '\t' doesn't go inside it for many WELL
 > documented reasons.
 
 Cite documentation please and explain where I got it wrong.
 
 > Furthermore sed mathes '\t' without [] so why bother filing a bug against []
 > ?
 
 The point was to match one or the other as this was something that
 someone else wrote that's a valid regular expression in bracket
 notation that I executed on both FreeBSD and Linux. '\040' != '\011'
 and as such a space shouldn't be a drop in replacement for a
 horizontal tab. The PR was filed to note the discrepancy.
 
 Thanks,
 -Garrett
>Unformatted:
