Skip to content

Commit 55fe7b2

Browse files
authored
fortune: bad assumption in find_path() (#963)
* This version of fortune can be passed a file argument, which will be used as the fortune file * In find_path(), if the direct path check fails a loop is entered where the file argument is appended to each search directory * When the file argument is an absolute path, entering this loop is incorrect because the absolute path will be prefixed with the search directory path * fortune's debug (-d) option makes the file search easy to see * While here, use catfile() to join relative paths with the search directory
1 parent 0155ad1 commit 55fe7b2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

bin/fortune

+7-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ License: gpl
1515
use strict;
1616
use FindBin qw($Bin);
1717
use File::Basename;
18+
use File::Spec;
1819
use Getopt::Std;
1920

2021
$|++;
2122

22-
my ($VERSION) = '2.1';
23+
my ($VERSION) = '2.2';
2324

2425
my $home = $Bin;
2526
$home =~ s|/[^/]*/?$||;
@@ -232,8 +233,11 @@ sub find_path
232233

233234
return $name if -d $name || is_fortune_file( $name );
234235

235-
foreach ( fortune_dirs() ) {
236-
return "$_/$name" if is_fortune_file( "$_/$name" );
236+
unless (File::Spec->file_name_is_absolute($name)) {
237+
foreach ( fortune_dirs() ) {
238+
my $abs = File::Spec->catfile($_, $name);
239+
return $abs if is_fortune_file($abs);
240+
}
237241
}
238242

239243
die "fortune: $name not a fortune file or directory\n";

0 commit comments

Comments
 (0)