From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 75B491FEAA for ; Sat, 25 Jun 2016 21:36:52 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] view: safer and optional quoting for --in-reply-to arg Date: Sat, 25 Jun 2016 21:36:52 +0000 Message-Id: <20160625213652.6677-1-e@80x24.org> List-Id: Angle brackets around the --in-reply-to= arg for git send-email has been optional since git v1.5.3.2, so strip them and make the command-line argument easier-to-type. --- lib/PublicInbox/View.pm | 11 ++++++++++- t/view.t | 14 +++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 30d8e3e..38e35bf 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -455,6 +455,15 @@ sub _parent_headers { $rv; } +sub squote_maybe ($) { + my ($val) = @_; + if ($val =~ m{([^\w@\./,\%\+\-])}) { + $val =~ s/(['!])/'\\$1'/g; # '!' for csh + return "'$val'"; + } + $val; +} + sub mailto_arg_link { my ($hdr) = @_; my %cc; # everyone else @@ -475,7 +484,7 @@ sub mailto_arg_link { my $subj = $hdr->header('Subject') || ''; $subj = "Re: $subj" unless $subj =~ /\bRe:/i; my $mid = $hdr->header_raw('Message-ID'); - push @arg, "--in-reply-to='" . ascii_html($mid) . "'"; + push @arg, '--in-reply-to='.ascii_html(squote_maybe(mid_clean($mid))); my $irt = uri_escape_utf8($mid); delete $cc{$to}; push @arg, '--to=' . ascii_html($to); diff --git a/t/view.t b/t/view.t index 4ce3c77..8a898fe 100644 --- a/t/view.t +++ b/t/view.t @@ -4,8 +4,20 @@ use strict; use warnings; use Test::More; use Email::MIME; -use PublicInbox::View; use Plack::Util; +use_ok 'PublicInbox::View'; + +my @q = ( + 'foo@bar', 'foo@bar', + 'a b', "'a b'", + "a'b", "'a'\\''b'", +); +while (@q) { + my $input = shift @q; + my $expect = shift @q; + my $res = PublicInbox::View::squote_maybe($input); + is($res, $expect, "quote $input => $res"); +} # FIXME: make this test less fragile my $ctx = { -- EW