From: Joey Hess Date: Thu, 26 Mar 2009 20:45:53 +0000 (-0400) Subject: comments: Fix anchor ids to be legal xhtml. Closes: #521339 X-Git-Tag: 3.09~43 X-Git-Url: http://git.tremily.us/?p=ikiwiki.git;a=commitdiff_plain;h=10822a22b3d8872afb31e1847ee7448af86c574d 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. --- 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 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 @@ -
+