My fix to support encoded underscores in page titles broke links to pages

with underscores in their filenames, since the link code also used
titlepage. Create a new linkpage function and have the link code use that
instead.
master
joey 2007-03-07 09:48:59 +00:00
parent b39495f501
commit b365d864c5
6 changed files with 29 additions and 17 deletions

View File

@ -376,6 +376,12 @@ sub titlepage ($) { #{{{
return $title;
} #}}}
sub linkpage ($) { #{{{
my $link=shift;
$link=~s/([^-[:alnum:]:+\/._])/$1 eq ' ' ? '_' : "__".ord($1)."__"/eg;
return $link;
} #}}}
sub cgiurl (@) { #{{{
my %params=@_;
@ -422,6 +428,8 @@ sub htmllink ($$$;@) { #{{{
my $link=shift;
my %opts=@_;
print STDERR "bestlink $lpage $link\n" if $lpage eq "roadmap" && $link =~/rcs/;
my $bestlink;
if (! $opts{forcesubpage}) {
$bestlink=bestlink($lpage, $link);
@ -496,8 +504,8 @@ sub linkify ($$$) { #{{{
$content =~ s{(\\?)$config{wiki_link_regexp}}{
defined $2
? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, titlepage($3), anchor => $4, linktext => pagetitle($2)))
: ( $1 ? "[[$3]]" : htmllink($lpage, $page, titlepage($3), anchor => $4))
? ( $1 ? "[[$2|$3]]" : htmllink($lpage, $page, linkpage($3), anchor => $4, linktext => pagetitle($2)))
: ( $1 ? "[[$3]]" : htmllink($lpage, $page, linkpage($3), anchor => $4))
}eg;
return $content;

View File

@ -286,9 +286,10 @@ sub cgi_prefs ($$) { #{{{
}
} #}}}
sub cgi_editpage ($$) { #{{{
sub cgi_editpage ($$;$) { #{{{
my $q=shift;
my $session=shift;
my $blogpost=shift;
my @fields=qw(do rcsinfo subpage from page type editcontent comments
newfile);
@ -322,6 +323,9 @@ sub cgi_editpage ($$) { #{{{
# characters.
my ($page)=$form->field('page');
$page=titlepage(possibly_foolish_untaint($page));
if ($blogpost) {
$page=~s/(\/)/"__".ord($1)."__"/eg;
}
if (! defined $page || ! length $page || file_pruned($page, $config{srcdir}) || $page=~/^\//) {
error("bad page name");
}
@ -682,7 +686,6 @@ sub cgi (;$$) { #{{{
}
elsif ($do eq 'blog') {
my $page=decode_utf8($q->param('title'));
$page=~s/\// /g; # remove slashes to avoid accidental subpages
# if the page already exists, munge it to be unique
my $from=$q->param('from');
my $add="";
@ -691,9 +694,9 @@ sub cgi (;$$) { #{{{
$add++;
}
$q->param('page', $page.$add);
# now run same as create
# now run same as create, except escape slashes too
$q->param('do', 'create');
cgi_editpage($q, $session);
cgi_editpage($q, $session, 1);
}
elsif ($do eq 'postsignin') {
error(gettext("login failed, perhaps you need to turn on cookies?"));

View File

@ -157,7 +157,7 @@ sub scan ($) { #{{{
my @links;
while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
push @links, titlepage($2);
push @links, linkpage($2);
}
if ($config{discussion}) {
# Discussion links are a special case since they're

2
debian/changelog vendored
View File

@ -18,7 +18,7 @@ ikiwiki (1.45) UNRELEASED; urgency=low
* Fix some nasty issues with page name escaping during previewing
(introduced in 1.44).
-- Joey Hess <joeyh@debian.org> Wed, 7 Mar 2007 03:59:39 -0500
-- Joey Hess <joeyh@debian.org> Wed, 7 Mar 2007 04:47:40 -0500
ikiwiki (1.44) unstable; urgency=low

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2007-03-07 02:29-0500\n"
"POT-Creation-Date: 2007-03-07 04:47-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -24,33 +24,33 @@ msgstr ""
msgid "Preferences saved."
msgstr ""
#: ../IkiWiki/CGI.pm:340
#: ../IkiWiki/CGI.pm:344
#, perl-format
msgid "%s is not an editable page"
msgstr ""
#: ../IkiWiki/CGI.pm:427 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/CGI.pm:431 ../IkiWiki/Plugin/brokenlinks.pm:24
#: ../IkiWiki/Plugin/inline.pm:172 ../IkiWiki/Plugin/opendiscussion.pm:17
#: ../IkiWiki/Plugin/orphans.pm:28 ../IkiWiki/Render.pm:97
#: ../IkiWiki/Render.pm:165
msgid "discussion"
msgstr ""
#: ../IkiWiki/CGI.pm:473
#: ../IkiWiki/CGI.pm:477
#, perl-format
msgid "creating %s"
msgstr ""
#: ../IkiWiki/CGI.pm:490 ../IkiWiki/CGI.pm:526 ../IkiWiki/CGI.pm:570
#: ../IkiWiki/CGI.pm:494 ../IkiWiki/CGI.pm:530 ../IkiWiki/CGI.pm:574
#, perl-format
msgid "editing %s"
msgstr ""
#: ../IkiWiki/CGI.pm:667
#: ../IkiWiki/CGI.pm:671
msgid "You are banned."
msgstr ""
#: ../IkiWiki/CGI.pm:699
#: ../IkiWiki/CGI.pm:702
msgid "login failed, perhaps you need to turn on cookies?"
msgstr ""
@ -486,7 +486,7 @@ msgstr ""
#. translators: preprocessor directive name,
#. translators: the second a page name, the
#. translators: third a number.
#: ../IkiWiki.pm:561
#: ../IkiWiki.pm:569
#, perl-format
msgid "%s preprocessing loop detected on %s at depth %i"
msgstr ""

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 15;
use Test::More tests => 16;
BEGIN { use_ok("IkiWiki"); }
@ -68,6 +68,7 @@ sub links_text ($$) {
ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "bar"])), "ok link");
ok(links_to("bar_baz", linkify("foo", "foo", "link to [[bar_baz]] ok", ["foo", "bar_baz"])), "ok link");
ok(not_links_to("bar", linkify("foo", "foo", "link to \\[[bar]] ok", ["foo", "bar"])), "escaped link");
ok(links_to("page=bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo"])), "broken link");
ok(links_to("bar", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");