Skip to content

Commit fc8a812

Browse files
carenasgitster
authored andcommitted
add -p: avoid use of undefined $key when ReadKey -> EOF
b5cc003 (add -i: ignore terminal escape sequences, 2011-05-17) add an additional check to the original code to better handle keys for escape sequences, but failed to account for the possibility the first ReadKey call returned undef (ex: stdin closes) and that was being handled fine by the original code in ca6ac7f (add -p: prompt for single characters, 2009-02-05) Add a test for undefined and encapsulate the loop and the original print that relied on it within it. After this, the following command (in a suitable repository state) wouldn't print any error: $ git -c interactive.singleKey add -p </dev/null Signed-off-by: Carlo Marcelo Arenas Belón <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 94f6e3e commit fc8a812

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

git-add--interactive.perl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,17 @@ sub prompt_single_character {
11751175
ReadMode 'cbreak';
11761176
my $key = ReadKey 0;
11771177
ReadMode 'restore';
1178-
if ($use_termcap and $key eq "\e") {
1179-
while (!defined $term_escapes{$key}) {
1180-
my $next = ReadKey 0.5;
1181-
last if (!defined $next);
1182-
$key .= $next;
1178+
if (defined $key) {
1179+
if ($use_termcap and $key eq "\e") {
1180+
while (!defined $term_escapes{$key}) {
1181+
my $next = ReadKey 0.5;
1182+
last if (!defined $next);
1183+
$key .= $next;
1184+
}
1185+
$key =~ s/\e/^[/;
11831186
}
1184-
$key =~ s/\e/^[/;
1187+
print "$key";
11851188
}
1186-
print "$key" if defined $key;
11871189
print "\n";
11881190
return $key;
11891191
} else {

0 commit comments

Comments
 (0)