From e0cd19f30b5cc66450bdb52bd9840c6d8fa774eb Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Sun, 21 Dec 2008 16:32:44 +0000
Subject: openid: in &openiduser, let domain-style providers have arbitrarily
many subdomains
This leads to better display for OpenIDs like smcv.pseudorandom.co.uk
and thm.id.fedoraproject.org (to take a couple of examples from the
IkiWiki commit history).
---
IkiWiki/Plugin/openid.pm | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index 2933c9ed9..4acfecf5e 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -191,9 +191,10 @@ 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]".
if ($display !~ /\[/) {
--
cgit v1.2.3
From 801dc76bf0e066558cc6ea179073104fb6a67c92 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Sun, 21 Dec 2008 16:35:02 +0000
Subject: openid: in &openiduser, allow subdirectory-style providers to end
with '/'
This improves the display of OpenIDs like 'http://id.mayfirst.org/jamie/'
(taking an example from the IkiWiki commit log).
---
IkiWiki/Plugin/openid.pm | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/IkiWiki/Plugin/openid.pm b/IkiWiki/Plugin/openid.pm
index 4acfecf5e..574c42f0e 100644
--- a/IkiWiki/Plugin/openid.pm
+++ b/IkiWiki/Plugin/openid.pm
@@ -197,8 +197,9 @@ sub openiduser ($) {
$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'};
--
cgit v1.2.3
From f0c76aa51ca7a1dbfb8fcfa679baa114e563b895 Mon Sep 17 00:00:00 2001
From: Simon McVittie
Date: Sun, 21 Dec 2008 16:37:20 +0000
Subject: Add a regression test for &openiduser
---
t/openiduser.t | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100755 t/openiduser.t
diff --git a/t/openiduser.t b/t/openiduser.t
new file mode 100755
index 000000000..fe4d2b445
--- /dev/null
+++ b/t/openiduser.t
@@ -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]');
--
cgit v1.2.3