Skip to content

Commit

Permalink
git-send-email.perl: Handle shell metacharacters in $EDITOR properly
Browse files Browse the repository at this point in the history
This fixes the git-send-perl semantics for launching an editor when
$GIT_EDITOR (or friends) contains shell metacharacters to match
launch_editor() in builtin-tag.c. If we use the current approach
(sh -c '$0 $@' "$EDITOR" files ...), we see it fails when $EDITOR has
shell metacharacters:

  $ sh -x -c '$0 $@' "$VISUAL" "foo"
  + "$FAKE_EDITOR" foo
  "$FAKE_EDITOR": 1: "$FAKE_EDITOR": not found

Whereas builtin-tag.c will invoke sh -c "$EDITOR \"$@\"".

Thus, this patch changes git-send-email.perl to use the same method as the
C utilities, and additionally updates t/t9001-send-email.sh to test for
this bug.

Signed-off-by: Bryan Donlan <bdonlan@fushizen.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Bryan Donlan authored and Junio C Hamano committed May 5, 2008
1 parent e5c349b commit 065096c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion git-send-email.perl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ sub expand_aliases {
close(C);

my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
system('sh', '-c', '$0 $@', $editor, $compose_filename);
system('sh', '-c', $editor.' "$@"', $editor, $compose_filename);

open(C2,">",$compose_filename . ".final")
or die "Failed to open $compose_filename.final : " . $!;
Expand Down
8 changes: 6 additions & 2 deletions t/t9001-send-email.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,19 @@ test_expect_success 'Valid In-Reply-To when prompting' '

test_expect_success 'setup fake editor' '
(echo "#!/bin/sh" &&
echo "echo fake edit >>\$1"
echo "echo fake edit >>\"\$1\""
) >fake-editor &&
chmod +x fake-editor
'

FAKE_EDITOR="$(pwd)/fake-editor"
export FAKE_EDITOR
GIT_EDITOR='"$FAKE_EDITOR"'
export GIT_EDITOR

test_expect_success '--compose works' '
clean_fake_sendmail &&
echo y | \
GIT_EDITOR=$(pwd)/fake-editor \
GIT_SEND_EMAIL_NOTTY=1 \
git send-email \
--compose --subject foo \
Expand Down

0 comments on commit 065096c

Please sign in to comment.