git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] Add / command in add --patch (feature request)

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2008, 22:54 UTC
Message-ID
<7vod02cd3p.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20081126223858.GB10786@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 20 quoted lines
> On Wed, Nov 26, 2008 at 08:51:20PM +0000, William Pursell wrote:
>
>> This is naive, and it is easy for an invalid
>> search string to cause a perl error.
>> [...]
>> +			if( $text !~ $search_s ) {
>
> Yeah, a bad regex will cause the whole program to barf. Maybe wrap it in
> an eval, like this?
>
>   my $r = eval { $text !~ $search_s };
>   if ($@) {
>     print STDERR "error in search string: $@\n";
>     next;
>   }
>   if ($r) {
>     ...
>
> Or similar (I didn't look at the code closely enough to know if "next"
> is the right thing there).

Use of eval is a good way to protect against this kind of breakage, but it should be done close to where the string is given by the user, perhaps in here:

+ elsif ($line =~ m|^/(.*)|) { + $search_s = $1; + }

Something like...
	elsif ($line =~ m|^/(.*)|) {
        	$search_string = $1;
                eval {
                	$search_string =~ /$search_string/;
		};
                if ($@) {
                	print STDERR "Regexp error in $search_string: $@";
			next;
		}
	...
Previous: Jeff KingNext: William Pursell
Message 4 of 7 in “Add / command in add --patch (feature request)”
  1. 1/2 Add / command in add --patch (feature request)William Pursell, Nov 26, 2008
  2. Junio C HamanoNov 26, 2008
  3. Jeff KingNov 26, 2008
  4. Junio C HamanoNov 26, 2008
  5. William PursellNov 27, 2008
  6. Junio C HamanoNov 27, 2008
  7. Johannes SchindelinNov 27, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.