From: Joey Hess Date: Wed, 7 Jan 2009 17:06:29 +0000 (-0500) Subject: don't pick worst anon method in authed mode X-Git-Url: https://git.madduck.net/code/myrepos.git/commitdiff_plain/60545177be81428ab485ff3bc1eb93895194c683?pf=code don't pick worst anon method in authed mode --- diff --git a/webcheckout b/webcheckout index 4841fee..6df790d 100755 --- a/webcheckout +++ b/webcheckout @@ -127,23 +127,26 @@ sub doit { sub better { my ($a, $b)=@_; - my $firstanon=$b; + my @anon; foreach my $r (@anon_urls) { if ($a->{href} =~ /$r/) { - $firstanon=$a; - last; + push @anon, $a; } elsif ($b->{href} =~ /$r/) { - $firstanon=$b; - last; + push @anon, $b; } } if ($want_auth) { - return $firstanon != $a; + # Whichever is authed is better. + return 1 if ! @anon || ! grep { $_ eq $a } @anon; + return 0 if ! grep { $_ eq $b } @anon; + # Neither is authed, so the better anon method wins. + return $anon[0] == $a; } else { - return $firstanon == $a; + # Better anon method wins. + return @anon && $anon[0] == $a; } }