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

Submitted by:  Gene Hightower <Digilicious>
Submitted on:  Thu 22 Jul 2010 12:05:40 AM UTC  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Invalid
Privacy: PublicAssigned 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>
Project 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>

 

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 25 Jul 2010 10:54:10 AM UTCbonziniStatusNone=>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
    Thu 22 Jul 2010 11:09:39 PM UTCericbSummaryGrep 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.1-cleanup1