user/dev discussion of public-inbox itself
 help / color / 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
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 index

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

Reply instructions:

You may reply publically 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: https://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

user/dev discussion of public-inbox itself

Archives are clonable:
	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.org/gmane.mail.public-inbox.general

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git