From 270cbd7cf52d95636da941799158dc000e4c2ffc Mon Sep 17 00:00:00 2001
From: Joey Hess <joey@kitenet.net>
Date: Wed, 5 Jan 2011 14:57:04 -0400
Subject: Fix redirect to use a full url.

Was broken (in theory) by baseurl changes in last release.
---
 IkiWiki/CGI.pm   | 18 +++++++++++++-----
 debian/changelog |  4 +++-
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index df5179834..bdd190d4b 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -58,19 +58,27 @@ sub showform_preview ($$$$;@) {
 	my $cgi=shift;
 	my %params=@_;
 
-	eval q{use URI};
-	# The base url needs to be a full URL. If urlto returns relative,
-	# force it absolute, using the same URL scheme used for the cgi.
-	my $baseurl = URI->new_abs(urlto($params{page}), $cgi->url);
+	# The base url needs to be a full URL, and urlto may return a path.
+	my $baseurl = absurl(urlto($params{page}), $cgi->url);
 
 	showform($form, $buttons, $session, $cgi, @_,
 		forcebaseurl => $baseurl);
 }
 
+# Forces a partial url (path only) to absolute, using the same
+# URL scheme as the CGI. Full URLs are left unchanged.
+sub absurl ($$) {
+	my $partialurl=shift;
+	my $q=shift;
+
+	eval q{use URI};
+	return URI->new_abs($partialurl, $q);
+}
+
 sub redirect ($$) {
 	my $q=shift;
 	eval q{use URI};
-	my $url=URI->new(shift);
+	my $url=URI->new(absurl(shift, $q));
 	if (! $config{w3mmode}) {
 		print $q->redirect($url);
 	}
diff --git a/debian/changelog b/debian/changelog
index baf3e1906..f9468f1c7 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,7 +3,9 @@ ikiwiki (3.20101232) UNRELEASED; urgency=low
   * tag: Do not include tagbase in rss/atom category tags. (Giuseppe Bilotta)
   * tag: Improve display of tags with a slash in their names.
     (Giuseppe Bilotta)
-  * Fix base url when previewing. Was broken by urlto changes in last release.
+  * Fix base url when previewing. Was broken by base changes in last release.
+  * Fix redirect to use a full url. Was broken (in theory) by baseurl
+    changes in last release.
 
  -- Joey Hess <joeyh@debian.org>  Tue, 04 Jan 2011 16:00:55 -0400
 
-- 
cgit v1.2.3