buggrep - Bugs: bug #30515, Grep now seems to interpret \s in...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #30515: Grep now seems to interpret \s in the regex as whitespace

Submitter:  Gene Hightower <Digilicious>
Submitted:  Thu 22 Jul 2010 12:05:40 AM UTC
   
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Invalid
Privacy:  Public Assigned to:  None
Open/Closed:  Closed

Thu 22 Jul 2010 11:09:39 PM UTC, comment #1: 

Thanks for the report.  However, \s is (intentionally) left unspecified by POSIX, so we are free to treat it as an extension.  Basically, older grep treated '\s' as an extension for 's'; while newer grep treats it as an extension requesting '[[:space:]]'.

The change was intentional, as part of moving grep to be closer to glibc's regex engine, but you are correct that 2.6.3 failed to document it very well.  However, this was rectified in git several days before your bug report:

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=3569576a3

If you want to match literal 's', use 's' rather than '\s' in the first place; by using an expression actually specified by POSIX, you will also make your grep usage portable to non-GNU versions of grep.


Eric Blake <ericb>
Group Member
Thu 22 Jul 2010 12:05:40 AM UTC, original submission:  

Grep now seems to interpret \s in the regex as whitespace.  This is
not how grep used to work, nor is it how grep is documented to work.

Old grep works fine:

$ grep --version
grep (GNU grep) 2.5.1

Copyright 1988, 1992-1999, 2000, 2001 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ echo s | grep -c '^\s$'
1
$ echo " " | grep -c '^\s$'
0

New grep is broken:

$ grep --version
GNU grep 2.6.3

Copyright (C) 2009 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.

$ echo s | grep -c '^\s$'
0
$ echo " " | grep -c '^\s$'
1

Gene Hightower <Digilicious>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bonzini (Updated the item)
  • -email is unavailable- added by ericb (Posted a comment)
  • -email is unavailable- added by Digilicious (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2010-07-25 bonzini StatusNone Invalid
        Open/ClosedOpen Closed
        SummaryGrep now seems to interpret \\s in the regex as whitespace Grep now seems to interpret \s in the regex as whitespace
    2010-07-22 ericb SummaryGrep now seems to interpret \\s in the regex as whitespace Grep now seems to interpret \s in the regex as whitespace

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code