aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2016-01-21 08:40:14 +0000
committerSimon McVittie <smcv@debian.org>2016-01-21 08:40:14 +0000
commit7aca0d40a359e0b9b31b7dc9327dba76da51c85c (patch)
tree37dc9e2aed5882cea922e1a13f6a920e53304253
parent816c856a46dd2df6b763a72dd512849c5396e61d (diff)
downloadikiwiki-7aca0d40a359e0b9b31b7dc9327dba76da51c85c.tar
ikiwiki-7aca0d40a359e0b9b31b7dc9327dba76da51c85c.tar.gz
Compose relative URLs in RSS feeds correctly
If the relative link from the (page generating the) RSS to the target would start with "./" or "../", just concatenating it with the URL to the directory containing the RSS is not sufficient. Go via URI::new_abs to fix this.
-rw-r--r--IkiWiki/Plugin/inline.pm2
-rw-r--r--doc/bugs/rss_output_relative_links.mdwn2
-rwxr-xr-xt/inline.t20
3 files changed, 23 insertions, 1 deletions
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index 5ea5f35af..c3895d982 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -613,7 +613,7 @@ sub absolute_urls ($$) {
$v=$baseurl.$v; # anchor
}
elsif ($dv=~/^(?!\w+:)[^\/]/) {
- $v=$url.$v; # relative url
+ $v=URI->new_abs($v, $url)->canonical; # relative url
}
elsif ($dv=~/^\//) {
if (! defined $urltop) {
diff --git a/doc/bugs/rss_output_relative_links.mdwn b/doc/bugs/rss_output_relative_links.mdwn
index ff607cbb3..7a2e4d12b 100644
--- a/doc/bugs/rss_output_relative_links.mdwn
+++ b/doc/bugs/rss_output_relative_links.mdwn
@@ -1,3 +1,5 @@
RSS output contains relative links. Ie.
http://kitenet.net/~joey/blog/index.rss contains a link to
http://kitenet.net/~joey/blog/../blog.html
+
+> Finally [[done]] for the first release of 2016. --[[smcv]]
diff --git a/t/inline.t b/t/inline.t
index 859e1701a..8c0f1c35a 100755
--- a/t/inline.t
+++ b/t/inline.t
@@ -46,6 +46,9 @@ write_old_file("antagonists.mdwn",
# using old spelling of "limit" ("show") to verify backwards compat
write_old_file("enemies.mdwn",
'[[!inline pages="enemies/*" postform=no rootpage=enemies sort=title reverse=yes show=2]]');
+# to test correct processing of ../
+write_old_file("blah/blah/enemies.mdwn",
+ '[[!inline pages="enemies/*" postform=no rootpage=enemies sort=title reverse=yes show=2]]');
foreach my $page (qw(protagonists/shepard protagonists/link
antagonists/saren antagonists/ganondorf
friends/garrus friends/liara friends/midna friends/telma
@@ -53,6 +56,9 @@ foreach my $page (qw(protagonists/shepard protagonists/link
enemies/zant)) {
write_old_file("$page.mdwn", "this page is {$page}");
}
+# test cross-linking between pages as rendered in RSS
+write_old_file("enemies/zant.mdwn", "this page is {enemies/zant}\n\n".
+ "Zant hates [[friends/Midna]].");
ok(! system(@command));
ok(! system(@command, "--refresh"));
@@ -81,4 +87,18 @@ like($blob, qr[this page is \{enemies/zant}.*this page is \{enemies/rachni}]s,
unlike($blob, qr{enemies/(?:benezia|geth)},
'pages excluded by show should not be present');
+$blob = readfile("t/tmp/out/enemies.rss");
+like($blob, qr[this page is \{enemies/zant}.*this page is \{enemies/rachni}]s,
+ 'first two pages in reversed sort order are present');
+like($blob,
+ qr[Zant hates &lt;a href=(?:['"]|&quot;)http://example\.com/friends/midna.html(?:['"]|&quot;)&gt;Midna&lt;/a&gt;]s,
+ 'link is correctly relative');
+
+$blob = readfile("t/tmp/out/blah/blah/enemies.rss");
+like($blob, qr[this page is \{enemies/zant}.*this page is \{enemies/rachni}]s,
+ 'first two pages in reversed sort order are present');
+like($blob,
+ qr[Zant hates &lt;a href=(?:['"]|&quot;)http://example\.com/friends/midna.html(?:['"]|&quot;)&gt;Midna&lt;/a&gt;]s,
+ 'link is correctly relative');
+
done_testing;