user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/1] t/edit: use PublicInbox::Git::qx for pathname safety
Date: Mon, 4 Nov 2019 11:28:29 +0000	[thread overview]
Message-ID: <20191104112829.GA29645@dcvr> (raw)
In-Reply-To: <20191104111347.26737-1-e@80x24.org>

Another case where spaces can be in TMPDIR and cause
shell expansion with `command` to fail.
---
 t/edit.t | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/t/edit.t b/t/edit.t
index 1e9597f1..5cb66a65 100644
--- a/t/edit.t
+++ b/t/edit.t
@@ -41,7 +41,7 @@ my $mid = mid_clean($mime->header('Message-Id'));
 ok($im->add($mime), 'add message to be edited');
 $im->done;
 my ($in, $out, $err, $cmd, $cur, $t);
-my $__git_dir = "--git-dir=$ibx->{inboxdir}/git/0.git";
+my $git = PublicInbox::Git->new("$ibx->{inboxdir}/git/0.git");
 
 $t = '-F FILE'; {
 	$in = $out = $err = '';
@@ -65,7 +65,7 @@ $t = '-m MESSAGE_ID'; {
 
 $t = 'no-op -m MESSAGE_ID'; {
 	$in = $out = $err = '';
-	my $before = `git $__git_dir rev-parse HEAD`;
+	my $before = $git->qx(qw(rev-parse HEAD));
 	local $ENV{MAIL_EDITOR} = "$^X -i -p -e 's/bool pfx/boolean prefix/'";
 	$cmd = [ "$cmd_pfx-edit", "-m$mid", $inboxdir ];
 	ok(run($cmd, \$in, \$out, \$err), "$t succeeds");
@@ -75,13 +75,13 @@ $t = 'no-op -m MESSAGE_ID'; {
 	like($cur->header('Subject'), qr/boolean prefix/,
 		"$t does not change message");
 	like($out, qr/NONE/, 'noop shows NONE');
-	my $after = `git $__git_dir rev-parse HEAD`;
+	my $after = $git->qx(qw(rev-parse HEAD));
 	is($after, $before, 'git head unchanged');
 }
 
 $t = 'no-op -m MESSAGE_ID w/Status: header'; { # because mutt does it
 	$in = $out = $err = '';
-	my $before = `git $__git_dir rev-parse HEAD`;
+	my $before = $git->qx(qw(rev-parse HEAD));
 	local $ENV{MAIL_EDITOR} =
 			"$^X -i -p -e 's/^Subject:.*/Status: RO\\n\$&/'";
 	$cmd = [ "$cmd_pfx-edit", "-m$mid", $inboxdir ];
@@ -93,13 +93,12 @@ $t = 'no-op -m MESSAGE_ID w/Status: header'; { # because mutt does it
 		"$t does not change message");
 	is($cur->header('Status'), undef, 'Status header not added');
 	like($out, qr/NONE/, 'noop shows NONE');
-	my $after = `git $__git_dir rev-parse HEAD`;
+	my $after = $git->qx(qw(rev-parse HEAD));
 	is($after, $before, 'git head unchanged');
 }
 
 $t = '-m MESSAGE_ID can change Received: headers'; {
 	$in = $out = $err = '';
-	my $before = `git $__git_dir rev-parse HEAD`;
 	local $ENV{MAIL_EDITOR} =
 			"$^X -i -p -e 's/^Subject:.*/Received: x\\n\$&/'";
 	$cmd = [ "$cmd_pfx-edit", "-m$mid", $inboxdir ];
@@ -187,7 +186,7 @@ $t .= ' and --force'; {
 	$cmd = [ "$cmd_pfx-edit", "-m$mid", '--force', $inboxdir ];
 	ok(run($cmd, \$in, \$out, \$err), "$t succeeds");
 	like($err, qr/Will edit all of them/, "$t notes all will be edited");
-	my @dump = `git $__git_dir cat-file --batch --batch-all-objects`;
+	my @dump = $git->qx(qw(cat-file --batch --batch-all-objects));
 	chomp @dump;
 	is_deeply([grep(/^Subject:/i, @dump)], [qw(Subject:x Subject:x)],
 		"$t edited both messages");

      reply	other threads:[~2019-11-04 11:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-04 11:13 [PATCH] tests: rely on PublicInbox::Git for pathname safety Eric Wong
2019-11-04 11:28 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191104112829.GA29645@dcvr \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).