git-send-email.perl: Handle shell metacharacters in $EDITOR properly
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>
Bryan Donlan committed
May 4, 2008 at 01:37 UTC
065096c2b558af80e670299621ff3ddc6839954c
2 files changed
+7
-3
git-send-email.perl
+1
-1
@@ -512,7 +512,7 @@ EOT
512
close(C);
513
514
my $editor = $ENV{GIT_EDITOR} || Git::config(@repo, "core.editor") || $ENV{VISUAL} || $ENV{EDITOR} || "vi";
515
- system('sh', '-c', '$0 $@', $editor, $compose_filename);
515
+ system('sh', '-c', $editor.' "$@"', $editor, $compose_filename);
516
517
open(C2,">",$compose_filename . ".final")
518
or die "Failed to open $compose_filename.final : " . $!;
t/t9001-send-email.sh
+6
-2
@@ -139,15 +139,19 @@ test_expect_success 'Valid In-Reply-To when prompting' '
139
140
test_expect_success 'setup fake editor' '
141
(echo "#!/bin/sh" &&
142
- echo "echo fake edit >>\$1"
142
+ echo "echo fake edit >>\"\$1\""
143
) >fake-editor &&
144
chmod +x fake-editor
145
'
146
147
+FAKE_EDITOR="$(pwd)/fake-editor"
148
+export FAKE_EDITOR
149
+GIT_EDITOR='"$FAKE_EDITOR"'
150
+export GIT_EDITOR
151
+
152
test_expect_success '--compose works' '
153
clean_fake_sendmail &&
154
echo y | \
150
- GIT_EDITOR=$(pwd)/fake-editor \
155
GIT_SEND_EMAIL_NOTTY=1 \
156
git send-email \
157
--compose --subject foo \