CC: | magnus [...] trapd00r.se |
Subject: | vi-mode breakage when searching with f, F, t, T |
When using the vi mode, defined in ViCommand.pm, searching back and
forth with f, F, t or T breaks on characters like '(' and ')' since
they're evaluated as pattern metacharacters.
Attached is a patch that fixes this by matching all characters literally.
Subject: | ViCommand.pm.patch |
--- ViCommand.pm.orig 2004-11-22 14:09:23.000000000 +0100
+++ ViCommand.pm.fix 2011-01-20 17:57:11.283335132 +0100
@@ -537,12 +537,14 @@
my ($l, $x) = ( $$self{lines}[ $$self{pos}[1] ], $$self{pos}[0] );
if ($key eq 'T' or $key eq 'F') {
$l = substr($l, 0, $x);
- return $self->bell unless $l =~ /.*((?:$chr.*){$cnt})$/;
+ # We do not want $chr to be interpreted as pattern metacharacters
+ # Avoid 'unmatched "(" in regex'
+ return $self->bell unless $l =~ /.*((?:\Q$chr\E.*){$cnt})$/;
$$self{pos}[0] -= length($1) - (($key eq 'T') ? 1 : 0);
return length($1);
}
else { # ($key eq 't' || $key eq 'f')
- return $self->bell unless $l =~ /^..{$x}((?:.*?$chr){$cnt})/;
+ return $self->bell unless $l =~ /^..{$x}((?:.*?\Q$chr\E){$cnt})/;
$$self{pos}[0] += length($1) - (($key eq 't') ? 1 : 0);
return length($1);
}