From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 16 02:06:53 2016 Received: (at submit) by debbugs.gnu.org; 16 Jan 2016 07:06:53 +0000 Received: from localhost ([127.0.0.1]:50393 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aKKwn-0006ip-D8 for submit@debbugs.gnu.org; Sat, 16 Jan 2016 02:06:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56833) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aKKwl-0006ic-8E for submit@debbugs.gnu.org; Sat, 16 Jan 2016 02:06:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aKKwe-0002QH-Qk for submit@debbugs.gnu.org; Sat, 16 Jan 2016 02:06:45 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:56927) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKKwe-0002QD-Ni for submit@debbugs.gnu.org; Sat, 16 Jan 2016 02:06:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47798) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKKwd-0005X4-IS for bug-grep@gnu.org; Sat, 16 Jan 2016 02:06:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aKKwa-0002PV-9L for bug-grep@gnu.org; Sat, 16 Jan 2016 02:06:43 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:46081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aKKwa-0002PJ-0Q for bug-grep@gnu.org; Sat, 16 Jan 2016 02:06:40 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id AB1FC160E42 for ; Fri, 15 Jan 2016 23:06:36 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id ucjHuesiZQAl; Fri, 15 Jan 2016 23:06:35 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B1F441605E4; Fri, 15 Jan 2016 23:06:35 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id XAOPzrUaqH_J; Fri, 15 Jan 2016 23:06:35 -0800 (PST) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 8B6C5160017; Fri, 15 Jan 2016 23:06:35 -0800 (PST) From: Paul Eggert To: bug-grep@gnu.org Subject: [PATCH] grep: -x now supersedes -w more consistently Date: Fri, 15 Jan 2016 23:06:22 -0800 Message-Id: <1452927982-978-1-git-send-email-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.5.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.0 (----) X-Debbugs-Envelope-To: submit Cc: Paul Eggert X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.0 (----) * NEWS, doc/grep.texi (Matching Control): Mention this. * src/dfasearch.c (EGexecute): * src/pcresearch.c (Pcompile): Don't get confused by -w if -x is also present. * src/pcresearch.c (Pcompile): Remove misleading comment about non-UTF-8 multibyte locales, as PCRE doesn't support them. Calculate buffer sizes more carefully; the old method allocated a buffer slightly too big, seemingly due to luck. * tests/backref-word, tests/pcre: Add tests for this bug. --- NEWS | 5 ++++- doc/grep.texi | 1 + src/dfasearch.c | 6 +++--- src/pcresearch.c | 24 +++++++++++++----------- tests/backref-word | 4 ++++ tests/pcre | 5 ++++- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index a0f6bbb..9de7fcb 100644 --- a/NEWS +++ b/NEWS @@ -32,9 +32,12 @@ GNU grep NEWS -*- outline -*- This partly reverts the --exclude-related change in 2.22. [bug introduced in grep-2.22] - --line-buffer is no longer ineffective when combined with -l + --line-buffer is no longer ineffective when combined with -l. [bug introduced in grep-2.5] + -xw is now equivalent to -x more consistently, with -P and with backrefs. + [bug only partially fixed in grep-2.19] + * Noteworthy changes in release 2.22 (2015-11-01) [stable] diff --git a/doc/grep.texi b/doc/grep.texi index 76769b9..8883b27 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -233,6 +233,7 @@ Similarly, it must be either at the end of the line or followed by a non-word constituent character. Word-constituent characters are letters, digits, and the underscore. +This option has no effect if @option{-x} is also specified. @item -x @itemx --line-regexp diff --git a/src/dfasearch.c b/src/dfasearch.c index a330eac..e04a2df 100644 --- a/src/dfasearch.c +++ b/src/dfasearch.c @@ -363,14 +363,14 @@ EGexecute (char *buf, size_t size, size_t *match_size, len = end - ptr; goto assess_pattern_match; } - /* If -w, check if the match aligns with word boundaries. - We do this iteratively because: + /* If -w and not -x, check whether the match aligns with + word boundaries. Do this iteratively because: (a) the line may contain more than one occurrence of the pattern, and (b) Several alternatives in the pattern might be valid at a given point, and we may need to consider a shorter one to find a word boundary. */ - if (match_words) + if (!match_lines && match_words) while (match <= best_match) { regoff_t shorter_len = 0; diff --git a/src/pcresearch.c b/src/pcresearch.c index 1fae94d..3fee67a 100644 --- a/src/pcresearch.c +++ b/src/pcresearch.c @@ -98,7 +98,13 @@ Pcompile (char const *pattern, size_t size) #else int e; char const *ep; - char *re = xnmalloc (4, size + 7); + static char const wprefix[] = "(? $out || fail=1 compare exp1 $out || fail=1 + + LC_ALL=$LOC grep -wx '\(foo\) \1' exp1 > $out + test $? -eq 1 || fail=1 + compare /dev/null $out || fail=1 done Exit $fail diff --git a/tests/pcre b/tests/pcre index a9dfb4b..92e788e 100755 --- a/tests/pcre +++ b/tests/pcre @@ -1,5 +1,5 @@ #! /bin/sh -# Ensure that with -P, \s matches a newline. +# Simple PCRE tests. # # Copyright (C) 2001, 2006, 2009-2016 Free Software Foundation, Inc. # @@ -15,4 +15,7 @@ fail=0 echo | grep -P '\s*$' || fail=1 echo | grep -zP '\s$' || fail=1 +echo '.ab' | grep -Pwx ab +test $? -eq 1 || fail=1 + Exit $fail -- 2.5.0 From debbugs-submit-bounces@debbugs.gnu.org Sat Jan 16 02:08:11 2016 Received: (at control) by debbugs.gnu.org; 16 Jan 2016 07:08:11 +0000 Received: from localhost ([127.0.0.1]:50403 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aKKy3-0006m1-95 for submit@debbugs.gnu.org; Sat, 16 Jan 2016 02:08:11 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:59813) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aKKy1-0006lo-Tr for control@debbugs.gnu.org; Sat, 16 Jan 2016 02:08:10 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 349B7160017 for ; Fri, 15 Jan 2016 23:08:04 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id YgbpAV3_ghXE for ; Fri, 15 Jan 2016 23:08:03 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 928911605E4 for ; Fri, 15 Jan 2016 23:08:03 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 7MK3hyD9M6e8 for ; Fri, 15 Jan 2016 23:08:03 -0800 (PST) Received: from [192.168.1.9] (pool-100-32-155-148.lsanca.fios.verizon.net [100.32.155.148]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 686C5160017 for ; Fri, 15 Jan 2016 23:08:03 -0800 (PST) To: control@debbugs.gnu.org From: Paul Eggert Subject: 22382 is done already Organization: UCLA Computer Science Department Message-ID: <5699EC4F.4060902@cs.ucla.edu> Date: Fri, 15 Jan 2016 23:07:59 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) close 22382 From unknown Tue Jun 24 07:00:15 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 13 Feb 2016 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator