From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 681BC1F454; Mon, 4 Nov 2019 11:28:29 +0000 (UTC) Date: Mon, 4 Nov 2019 11:28:29 +0000 From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/1] t/edit: use PublicInbox::Git::qx for pathname safety Message-ID: <20191104112829.GA29645@dcvr> References: <20191104111347.26737-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20191104111347.26737-1-e@80x24.org> List-Id: 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");