]> sipb.mit.edu Git - ikiwiki.git/commitdiff
Merge commit 'smcv/openid'
authorJoey Hess <joey@gnu.kitenet.net>
Sun, 21 Dec 2008 18:13:28 +0000 (13:13 -0500)
committerJoey Hess <joey@gnu.kitenet.net>
Sun, 21 Dec 2008 18:13:28 +0000 (13:13 -0500)
IkiWiki/Plugin/openid.pm
t/openiduser.t [new file with mode: 0755]

index 2933c9ed99960dd8e5edece394f11a6b9b08f085..574c42f0ed83efd2e4e4690d2680a4cc1a92df56 100644 (file)
@@ -191,13 +191,15 @@ sub openiduser ($) {
            eval q{use Net::OpenID::VerifiedIdentity; 1} && !$@) {
                my $oid=Net::OpenID::VerifiedIdentity->new(identity => $user);
                my $display=$oid->display;
-               # Convert "user.somehost.com" to "user [somehost.com]".
+               # Convert "user.somehost.com" to "user [somehost.com]"
+               # (also "user.somehost.co.uk")
                if ($display !~ /\[/) {
-                       $display=~s/^(.*?)\.([^.]+\.[a-z]+)$/$1 [$2]/;
+                       $display=~s/^([-a-zA-Z0-9]+?)\.([-.a-zA-Z0-9]+\.[a-z]+)$/$1 [$2]/;
                }
                # Convert "http://somehost.com/user" to "user [somehost.com]".
+               # (also "https://somehost.com/user/")
                if ($display !~ /\[/) {
-                       $display=~s/^https?:\/\/(.+)\/([^\/]+)$/$2 [$1]/;
+                       $display=~s/^https?:\/\/(.+)\/([^\/]+)\/?$/$2 [$1]/;
                }
                $display=~s!^https?://!!; # make sure this is removed
                eval q{use CGI 'escapeHTML'};
diff --git a/t/openiduser.t b/t/openiduser.t
new file mode 100755 (executable)
index 0000000..fe4d2b4
--- /dev/null
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+BEGIN {
+       eval q{
+               use Net::OpenID::VerifiedIdentity;
+       };
+       if ($@) {
+               eval q{use Test::More skip_all => "Net::OpenID::VerifiedIdentity not available"};
+       }
+       else {
+               eval q{use Test::More tests => 9};
+       }
+       use_ok("IkiWiki::Plugin::openid");
+}
+
+# Some typical examples:
+
+is(IkiWiki::openiduser('http://josephturian.blogspot.com'), 'josephturian [blogspot.com]');
+is(IkiWiki::openiduser('http://yam655.livejournal.com/'), 'yam655 [livejournal.com]');
+is(IkiWiki::openiduser('http://id.mayfirst.org/jamie/'), 'jamie [id.mayfirst.org]');
+
+# and some less typical ones taken from the ikiwiki commit history
+
+is(IkiWiki::openiduser('http://thm.id.fedoraproject.org/'), 'thm [id.fedoraproject.org]');
+is(IkiWiki::openiduser('http://dtrt.org/'), 'dtrt.org');
+is(IkiWiki::openiduser('http://alcopop.org/me/openid/'), 'openid [alcopop.org/me]');
+is(IkiWiki::openiduser('http://id.launchpad.net/882/bielawski1'), 'bielawski1 [id.launchpad.net/882]');
+is(IkiWiki::openiduser('http://technorati.com/people/technorati/drajt'), 'drajt [technorati.com/people/technorati]');