From: Jeff King <peff@peff.net>
To: Michal Nazarewicz <mpn@google.com>
Cc: Junio C Hamano <gitster@pobox.com>,
Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
git@vger.kernel.org
Subject: Re: [PATCHv2 4/5] Git.pm: add interface for git credential command
Date: Fri, 8 Feb 2013 00:11:20 -0500 [thread overview]
Message-ID: <20130208051120.GD4157@sigill.intra.peff.net> (raw)
In-Reply-To: <78516627e893e54d5aafe0694d1face9a37893de.1360242782.git.mina86@mina86.com>
On Thu, Feb 07, 2013 at 03:01:20PM +0100, Michal Nazarewicz wrote:
> > There are a few disallowed characters, like "\n" in key or value, and
> > "=" in a key. They should never happen unless the caller is buggy, but
> > should we check and catch them here?
>
> I left it as is for now since it's not entairly clear to me what to
> do in all cases. In particular:
>
> - when reading, what to do if the line is " foo = bar ",
According to the spec, whitespace (except for the final newline) is not
significant, and that parses key=" foo ", value=" bar ". The spec could
ignore whitespace on the key side, but I intentionally did not in an
attempt to keep the protocol simple. Your original implementation did
the right thing already.
> - when reading, what to do if the line is "foo=" (ie. empty value),
The empty string is a valid value.
> - when writing, what to do if value is a single space,
Then it's a single space. It's the caller's problem whether that is an
issue or not.
> - when writing, what to do if value ends with a new line,
That's bogus. We cannot represent that value. I'd suggest to simply die,
as it is a bug in the caller (we _could_ try to be nice and assume the
caller accidentally forgot to chomp, but I'd rather be careful than
nice).
> - when writing, what to do if value is empty (currently not printed at all),
I think you should still print it. It's unlikely to matter, but
technically a helper response may override keys (or set them to blank),
and the intermediate state gets sent on to the next helper, if there are
multiple.
> On Thu, Feb 07 2013, Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> wrote:
> > I think you should credit git-remote-mediawiki for the code in the
> > commit message. Perhaps have a first "copy/paste" commit, and then an
> > "adaptation" commit to add sort, ^ anchor in regexp, doc and your
> > callback mechanism, but I won't insist on that.
>
> Good point. Creating additional commit is a bit too much for my
> licking, but added note in commit message.
I think that's fine.
> +sub _credential_read {
> + my %credential;
> + my ($reader, $op) = (@_);
> + while (<$reader>) {
> + if (!/^([^=\s]+)=(.*?)\s*$/) {
> + throw Error::Simple("unable to parse git credential $op response:\n$_");
> + }
> + $credential{$1} = $2;
I think this is worse than your previous version. The spec really is as
simple as:
while (<$reader>) {
last if /^$/; # blank line is OK as end-of-credential
/^([^=]+)=(.*)/
or throw Error::Simple(...);
$credential{$1} = {$2};
}
(actually, the spec as written does not explicitly forbid an empty key,
but it is nonsensical, and it might be worth updating the docs).
> +sub _credential_write {
> + my ($credential, $writer) = @_;
> +
> + for my $key (sort {
> + # url overwrites other fields, so it must come first
> + return -1 if $a eq 'url';
> + return 1 if $b eq 'url';
> + return $a cmp $b;
> + } keys %$credential) {
> + if (defined $credential->{$key} && length $credential->{$key}) {
> + print $writer $key, '=', $credential->{$key}, "\n";
> + }
When I mentioned error-checking the format, I really just meant
something like:
$key =~ /[=\n\0]/
and die "BUG: credential key contains invalid characters: $key";
if (defined $credential->{$key}) {
$credential->{$key} =~ /[\n\0]/
and die "BUG: credential value contains invalid characters: $credential->{key}";
print $writer $key, '=', $credential->{$key}, "\n";
}
Those dies should never happen, and are indicative of a bug in the
caller. We can't even represent them in the protocol, so we might as
well alert the user and die rather than trying to guess what the caller
intended.
-Peff
next prev parent reply other threads:[~2013-02-08 5:11 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-07 14:01 [PATCHv2 0/5] Make git-send-email use git-credential Michal Nazarewicz
2013-02-07 14:01 ` [PATCHv2 1/5] Git.pm: allow command_close_bidi_pipe to be called as method Michal Nazarewicz
2013-02-07 14:01 ` [PATCHv2 2/5] Git.pm: fix example in command_close_bidi_pipe documentation Michal Nazarewicz
2013-02-07 14:01 ` [PATCHv2 3/5] Git.pm: allow pipes to be closed prior to calling command_close_bidi_pipe Michal Nazarewicz
2013-02-07 14:01 ` [PATCHv2 4/5] Git.pm: add interface for git credential command Michal Nazarewicz
2013-02-07 18:46 ` Matthieu Moy
2013-02-07 23:38 ` Junio C Hamano
2013-02-08 1:37 ` Michal Nazarewicz
2013-02-08 5:11 ` Jeff King [this message]
2013-02-07 14:01 ` [PATCHv2 5/5] git-send-email: use git credential to obtain password Michal Nazarewicz
2013-02-07 18:42 ` Junio C Hamano
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130208051120.GD4157@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=mpn@google.com \
/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.
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 NNTP newsgroup(s).