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 <chriscool@xxxxxxxxxxxxx> --- t/t0021/rot13-filter.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/t/t0021/rot13-filter.pl b/t/t0021/rot13-filter.pl index 9e18be66b6..8f255b6131 100644 --- a/t/t0021/rot13-filter.pl +++ b/t/t0021/rot13-filter.pl @@ -93,15 +93,23 @@ sub packet_bin_read { } } -sub packet_txt_read { - my ( $res, $buf ) = packet_bin_read(); - if ( $res == -1 or $buf eq '' or $buf =~ s/\n$// ) { - return ( $res, $buf ); +sub remove_final_lf_or_die { + my $buf = shift; + if ( $buf =~ s/\n$// ) { + return $buf; } die "A non-binary line MUST be terminated by an LF.\n" . "Received: '$buf'"; } +sub packet_txt_read { + my ( $res, $buf ) = packet_bin_read(); + if ( $res != -1 and $buf ne '' ) { + $buf = remove_final_lf_or_die($buf); + } + return ( $res, $buf ); +} + # Read a text line and check that it is in the form "key=value" sub packet_key_val_read { my ( $key ) = @_; -- 2.15.0.132.g7ad97d78be