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.
master
Joey Hess 2009-03-26 16:45:53 -04:00
parent 3481a35953
commit 10822a22b3
3 changed files with 24 additions and 3 deletions

View File

@ -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 ($$;@) {

1
debian/changelog vendored
View File

@ -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

View File

@ -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>