* [PATCH] git-send-email: don't return undefined value in extract_valid_address()
@ 2012-11-20 12:20 Krzysztof Mazur
2012-11-20 20:27 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Mazur @ 2012-11-20 12:20 UTC (permalink / raw)
To: git; +Cc: Krzysztof Mazur
In the fallback check, when Email::Valid is not available, the
extract_valid_address() does not check for success of matching regex,
and $1, which can be undefined, is always returned. Now if match
fails an empty string is returned.
Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
---
This fixes following warnings:
Use of uninitialized value in string eq at ./git-send-email.perl line 1017.
Use of uninitialized value in quotemeta at ./git-send-email.perl line 1017.
W: unable to extract a valid address from: x a.patch
when invalid email address was added by --cc-cmd,
./git-send-email.perl --dry-run --to a@podlesie.net --cc-cmd=echo x a.patch
git-send-email.perl | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 5a7c29d..045f25f 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -831,12 +831,12 @@ sub extract_valid_address {
$address =~ s/^\s*<(.*)>\s*$/$1/;
if ($have_email_valid) {
return scalar Email::Valid->address($address);
- } else {
- # less robust/correct than the monster regexp in Email::Valid,
- # but still does a 99% job, and one less dependency
- $address =~ /($local_part_regexp\@$domain_regexp)/;
- return $1;
}
+
+ # less robust/correct than the monster regexp in Email::Valid,
+ # but still does a 99% job, and one less dependency
+ return $1 if $address =~ /($local_part_regexp\@$domain_regexp)/;
+ return "";
}
# Usually don't need to change anything below here.
--
1.8.0.283.gc57d856
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] git-send-email: don't return undefined value in extract_valid_address()
2012-11-20 12:20 [PATCH] git-send-email: don't return undefined value in extract_valid_address() Krzysztof Mazur
@ 2012-11-20 20:27 ` Junio C Hamano
2012-11-20 20:47 ` Krzysztof Mazur
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2012-11-20 20:27 UTC (permalink / raw)
To: Krzysztof Mazur; +Cc: git
Krzysztof Mazur <krzysiek@podlesie.net> writes:
> In the fallback check, when Email::Valid is not available, the
> extract_valid_address() does not check for success of matching regex,
> and $1, which can be undefined, is always returned. Now if match
> fails an empty string is returned.
That much we can read from the code, but a bigger question is why
would it be a good thing for the callers? Wouldn't they want to
be able to distinguish a failure from an empty string?
> Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
> ---
> This fixes following warnings:
> Use of uninitialized value in string eq at ./git-send-email.perl line 1017.
> Use of uninitialized value in quotemeta at ./git-send-email.perl line 1017.
> W: unable to extract a valid address from: x a.patch
>
> when invalid email address was added by --cc-cmd,
> ./git-send-email.perl --dry-run --to a@podlesie.net --cc-cmd=echo x a.patch
In other words, would we want to *hide* (not "fix") the warning?
Shouldn't we be barfing loudly and possibly erroring it out until
the user fixes her --cc-cmd?
> git-send-email.perl | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 5a7c29d..045f25f 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -831,12 +831,12 @@ sub extract_valid_address {
> $address =~ s/^\s*<(.*)>\s*$/$1/;
> if ($have_email_valid) {
> return scalar Email::Valid->address($address);
> - } else {
> - # less robust/correct than the monster regexp in Email::Valid,
> - # but still does a 99% job, and one less dependency
> - $address =~ /($local_part_regexp\@$domain_regexp)/;
> - return $1;
> }
> +
> + # less robust/correct than the monster regexp in Email::Valid,
> + # but still does a 99% job, and one less dependency
> + return $1 if $address =~ /($local_part_regexp\@$domain_regexp)/;
> + return "";
> }
>
> # Usually don't need to change anything below here.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] git-send-email: don't return undefined value in extract_valid_address()
2012-11-20 20:27 ` Junio C Hamano
@ 2012-11-20 20:47 ` Krzysztof Mazur
2012-11-20 22:14 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Mazur @ 2012-11-20 20:47 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Tue, Nov 20, 2012 at 12:27:36PM -0800, Junio C Hamano wrote:
> Krzysztof Mazur <krzysiek@podlesie.net> writes:
>
> > In the fallback check, when Email::Valid is not available, the
> > extract_valid_address() does not check for success of matching regex,
> > and $1, which can be undefined, is always returned. Now if match
> > fails an empty string is returned.
Maybe the last line of comment should be changed to:
fails an empty string is returned to indicate failure.
>
> That much we can read from the code, but a bigger question is why
> would it be a good thing for the callers? Wouldn't they want to
> be able to distinguish a failure from an empty string?
In this case returning empty string does not make sense, so it's
really used to indicate failure.
>
> > Signed-off-by: Krzysztof Mazur <krzysiek@podlesie.net>
> > ---
> > This fixes following warnings:
> > Use of uninitialized value in string eq at ./git-send-email.perl line 1017.
> > Use of uninitialized value in quotemeta at ./git-send-email.perl line 1017.
> > W: unable to extract a valid address from: x a.patch
> >
> > when invalid email address was added by --cc-cmd,
> > ./git-send-email.perl --dry-run --to a@podlesie.net --cc-cmd=echo x a.patch
>
> In other words, would we want to *hide* (not "fix") the warning?
> Shouldn't we be barfing loudly and possibly erroring it out until
> the user fixes her --cc-cmd?
>
Yes, it's just to hide the warning, the error (warning in this case) it's
already correctly generated:
W: unable to extract a valid address from: x a.patch
Maybe we should change it to an error?
Krzysiek
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] git-send-email: don't return undefined value in extract_valid_address()
2012-11-20 20:47 ` Krzysztof Mazur
@ 2012-11-20 22:14 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2012-11-20 22:14 UTC (permalink / raw)
To: Krzysztof Mazur; +Cc: git
Krzysztof Mazur <krzysiek@podlesie.net> writes:
> Yes, it's just to hide the warning, the error (warning in this case) it's
> already correctly generated:
>
> W: unable to extract a valid address from: x a.patch
But it is of no use if the message is sent out without the intended
recipient, no? It is too late when you notice it.
> Maybe we should change it to an error?
At least, when we are not giving the "final sanity check [Y/n]?"
prompt, I think the code should error out.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-20 22:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-20 12:20 [PATCH] git-send-email: don't return undefined value in extract_valid_address() Krzysztof Mazur
2012-11-20 20:27 ` Junio C Hamano
2012-11-20 20:47 ` Krzysztof Mazur
2012-11-20 22:14 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox