Tags:
create new tag
, view all tags

Bug: Search fails if started with Dash

Try performing a search that starts with a '-'. The - starting the search string is interpreted by the grep commands as more options. If I search for -T, I should return this page, but I get an empty result page. I will probably also get an error in the log files saying -T not a valid option.

I found this while writing a wrapper for bool to make it work better under TWiki.

Test case

Try searching for -T or -l in this web.

Environment

TWiki version: Current Alpha
TWiki plugins: N/A
Server OS: linux
Web server: Apache
Perl version: 5.6.1
Client OS: Windows 2000
Web Browser: Opera, IE

Possible Fix

If you add '--' after the option arguments to f/egrep and before the search string, most greps (and all posix greps) will do the right thing. The '--' means end of options and stops grep from trying to parse the search string as a series of options.

Looks like this patch fixes it.

diff -r1.1.1.3 Search.pm
204c204
<         $cmd = "%GREP% %SWITCHES% -l $TWiki::cmdQuote%TOKEN%$TWiki::cmdQuote %FILES%";
---
>         $cmd = "%GREP% %SWITCHES% -l -- $TWiki::cmdQuote%TOKEN%$TWiki::cmdQuote %FILES%";

-- JohnRouillard - 06 Aug 2002

Follow up

I've been running it for a few weeks now, and it works fine. I have tried the -- option on fgreps on sun solaris 2.8 and 2.6, SunOs 4.1.4, cygwin, Linux RedHat and Debian (Linux's and cygwin use gnu grep). Can somebody not operating on one of the above platforms check their f/egrep and see if there are any problems? It is possible older versions of HPOV, AIX, and Ultrix may be bitten by this. Its been too long for my memory to provide valid data for thes OS's.

-- JohnRouillard - 26 Aug 2002

Fix record

I think the '--' convention goes back quite a long way on Unix, and you've tested this widely already, so I've committed this to the TWikiAlphaRelease. Thanks for the patch!

-- RichardDonkin - 17 Oct 2002


Category: TWikiPatches
Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2005-02-15 - SamHasler
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.