difftool: sanitize $workdir as early as possible
authorDavid Aguilar <davvid@gmail.com>
Fri, 9 Dec 2016 08:58:46 +0000 (00:58 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Dec 2016 00:18:53 +0000 (16:18 -0800)
The double-slash fixup on the $workdir variable was being
performed just-in-time to avoid double-slashes in symlink
targets, but the rest of the code was silently using paths with
embedded "//" in them.

A recent user-reported error message contained double-slashes.
Eliminate the issue by sanitizing inputs as soon as they arrive.

Signed-off-by: David Aguilar <davvid@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-difftool.perl
index 959822d5f31f60c3b3366292c973e26f0948c45a..17c336321f30a8212ccdfbd9a4279832aecef6a4 100755 (executable)
@@ -224,9 +224,7 @@ sub setup_dir_diff
        delete($ENV{GIT_INDEX_FILE});
 
        # Changes in the working tree need special treatment since they are
-       # not part of the index. Remove any trailing slash from $workdir
-       # before starting to avoid double slashes in symlink targets.
-       $workdir =~ s|/$||;
+       # not part of the index.
        for my $file (@working_tree) {
                my $dir = dirname($file);
                unless (-d "$rdir/$dir") {
@@ -389,6 +387,7 @@ sub dir_diff
        my $repo = Git->repository();
        my $repo_path = $repo->repo_path();
        my $workdir = $repo->wc_path();
+       $workdir =~ s|/$||; # Avoid double slashes in symlink targets
        my ($a, $b, $tmpdir, @worktree) = setup_dir_diff($workdir, $symlinks);
 
        if (defined($extcmd)) {