aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-03-26 16:45:53 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-03-26 16:45:53 -0400
commit10822a22b3d8872afb31e1847ee7448af86c574d (patch)
tree77a47c4b3a38d69759c1b4faa47108b1daa4481d
parent3481a35953c0f8e858b382829c239411b06889c4 (diff)
downloadikiwiki-10822a22b3d8872afb31e1847ee7448af86c574d.tar
ikiwiki-10822a22b3d8872afb31e1847ee7448af86c574d.tar.gz
comments: Fix anchor ids to be legal xhtml. Closes: #521339
Well, that was a PITA. Luckily, this doesn't break guids to comments in rss feeds, though it does change the links. I haven't put in a warning about needing to rebuild to get this fix. It's probably good enough for new comments to get the fix, without a lot of mass rebuilding.
-rw-r--r--IkiWiki/Plugin/comments.pm24
-rw-r--r--debian/changelog1
-rw-r--r--templates/comment.tmpl2
3 files changed, 24 insertions, 3 deletions
diff --git a/IkiWiki/Plugin/comments.pm b/IkiWiki/Plugin/comments.pm
index 5782d9083..2ad422f5f 100644
--- a/IkiWiki/Plugin/comments.pm
+++ b/IkiWiki/Plugin/comments.pm
@@ -224,7 +224,7 @@ sub preprocess {
if ($params{page} =~ m/\/(\Q$config{comments_pagename}\E\d+)$/) {
$pagestate{$page}{meta}{permalink} = urlto(IkiWiki::dirname($params{page}), undef, 1).
- "#".$params{page};
+ "#".page_to_id($params{page});
}
eval q{use Date::Parse};
@@ -490,7 +490,8 @@ sub editcomment ($$) {
# Jump to the new comment on the page.
# The trailing question mark tries to avoid broken
# caches and get the most recent version of the page.
- IkiWiki::redirect($cgi, urlto($page, undef, 1)."?updated#$location");
+ IkiWiki::redirect($cgi, urlto($page, undef, 1).
+ "?updated#".page_to_id($location));
}
else {
@@ -759,6 +760,10 @@ sub pagetemplate (@) {
if (!exists $commentstate{$page}) {
return;
}
+
+ if ($template->query(name => 'commentid')) {
+ $template->param(commentid => page_to_id($page));
+ }
if ($template->query(name => 'commentuser')) {
$template->param(commentuser =>
@@ -808,6 +813,21 @@ sub unique_comment_location ($) {
return $location;
}
+sub page_to_id ($) {
+ # Converts a comment page name into a unique, legal html id
+ # addtibute value, that can be used as an anchor to link to the
+ # comment.
+ my $page=shift;
+
+ # It needs to start with a letter.
+ $page="comment_".$page;
+
+ # Encode any illegal characters.
+ $page=~s/([^A-Za-z0-9-_:.])/"__".ord($1)."__"/eg;
+
+ return $page;
+}
+
package IkiWiki::PageSpec;
sub match_postcomment ($$;@) {
diff --git a/debian/changelog b/debian/changelog
index 4ba32c8d6..158db9a4d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,7 @@ ikiwiki (3.09) UNRELEASED; urgency=low
* css: Add clear: both to inlinefooter.
* comments: Fix too loose test for comments pages that matched
normal pages with "comment_" in their name. Closes: #521322
+ * comments: Fix anchor ids to be legal xhtml. Closes: #521339
-- Joey Hess <joeyh@debian.org> Thu, 19 Mar 2009 15:32:49 -0400
diff --git a/templates/comment.tmpl b/templates/comment.tmpl
index 1b9064ea0..fb76ea004 100644
--- a/templates/comment.tmpl
+++ b/templates/comment.tmpl
@@ -1,4 +1,4 @@
-<div class="comment" id="<TMPL_VAR NAME=INLINEPAGE>">
+<div class="comment" id="<TMPL_VAR NAME=COMMENTID>">
<div class="comment-subject">
<TMPL_IF PERMALINK>