Skip to content

Commit

Permalink
Avoid puking out warning when calling trim_crlf with undef (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
siliconfeces authored Jul 23, 2024
1 parent ab38bde commit d8ee6f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/LANraragi/Utils/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ sub trim ($s) {

# Remove all newlines in a string
sub trim_CRLF ($s) {
$s =~ s/\R//g;
return $s;
if (defined($s)) {
$s =~ s/\R//g;
return $s;
}
return;
}

# Fixes up a URL string for use in the DL system.
Expand Down
6 changes: 6 additions & 0 deletions tests/LANraragi/Utils/String.t
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,11 @@ note('testing string similarity detection...');
is( LANraragi::Utils::String::most_similar( "orange", () ), undef, "Empty set" );
}

note('testing trim_crlf...');
{
is( LANraragi::Utils::String::trim_CRLF( undef ), undef, "Undef should return undef");
is( LANraragi::Utils::String::trim_CRLF( "a\nb" ), "ab", "newline should go bye");
}

done_testing();

0 comments on commit d8ee6f3

Please sign in to comment.