Skip to content

Commit 4a9ef1b

Browse files
chriscoolgitster
authored andcommitted
t0021/rot13-filter: refactor checking final lf
As checking for a lf character at the end of a buffer will be useful in another function, let's refactor this functionality into a small remove_final_lf_or_die() helper function. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 25cbfe3 commit 4a9ef1b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

t/t0021/rot13-filter.pl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,20 @@ sub packet_bin_read {
9393
}
9494
}
9595

96-
sub packet_txt_read {
97-
my ( $res, $buf ) = packet_bin_read();
98-
unless ( $res == -1 or $buf eq '' or $buf =~ s/\n$// ) {
96+
sub remove_final_lf_or_die {
97+
my $buf = shift;
98+
unless ( $buf =~ s/\n$// ) {
9999
die "A non-binary line MUST be terminated by an LF.\n"
100100
. "Received: '$buf'";
101101
}
102+
return $buf;
103+
}
104+
105+
sub packet_txt_read {
106+
my ( $res, $buf ) = packet_bin_read();
107+
unless ( $res == -1 or $buf eq '' ) {
108+
$buf = remove_final_lf_or_die($buf);
109+
}
102110
return ( $res, $buf );
103111
}
104112

0 commit comments

Comments
 (0)