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

View File

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

View File

@ -157,7 +157,7 @@ sub scan ($) { #{{{
my @links; my @links;
while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) { while ($content =~ /(?<!\\)$config{wiki_link_regexp}/g) {
push @links, titlepage($2); push @links, linkpage($2);
} }
if ($config{discussion}) { if ($config{discussion}) {
# Discussion links are a special case since they're # 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 * Fix some nasty issues with page name escaping during previewing
(introduced in 1.44). (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 ikiwiki (1.44) unstable; urgency=low

View File

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

View File

@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/perl
use warnings; use warnings;
use strict; use strict;
use Test::More tests => 15; use Test::More tests => 16;
BEGIN { use_ok("IkiWiki"); } 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", 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(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("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"); ok(links_to("bar", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");