Re: get_maintainer.pl: unexpected behaviour for path/to//file

From: Joe Perches
Date: Fri May 15 2020 - 08:31:15 EST


On Fri, 2020-05-15 at 11:52 +0100, Emil Velikov wrote:
> Hi Joe,
>
> Recently I've noticed that get_maintainer behaves differently if there
> is a double, sequential, forward slash in the path.
>
> AFAICT there should be no distinction between the two. Or at least many
> existing applications and scripts consider them one and the same.
>
> I've tried fixing this, although my perl isn't quite up-to scratch.
> Is this some weird bug or some intended feature?

Not really an intended feature.
The code counts slashes for directory depth.

I suppose it might be simpler to do this:
---
scripts/get_maintainer.pl | 1 +
1 file changed, 1 insertion(+)

diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index 6d973f3685f9..eaaf9373dbcf 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -538,6 +538,7 @@ foreach my $file (@ARGV) {
} elsif (!(-f $file)) {
die "$P: file '${file}' not found\n";
}
+ $file =~ s@//@/@g; # compress file double slashes
}
if ($from_filename || ($file ne "&STDIN" && vcs_file_exists($file))) {
$file =~ s/^\Q${cur_path}\E//; #strip any absolute path