po: Always filter .po files
The input to filter hooks is meant to be the content of a source file
on disk. If we only filter once per (page, destpage) pair, and a page
is inlined into the same destpage more than once, then the second
occurrence will render as the result of htmlizing .po source as if
it was Markdown (or whatever the type of the corresponding master page
is), which is never going to end well.
The alreadyfiltered mechanism was added in commit 1e874b3f
to avoid
preprocessing loops, but I'm not sure where it could lead to a loop:
filter hooks are only called from IkiWiki::filter, which is only called
on page content from disk or on proposed content being previewed.
According to <https://bugs.debian.org/911356#41>, deleting the
alreadyfiltered mechanism resolves the problem, as well as simplifying
the code.
Closes: #911356
Tested-by: intrigeri
master
parent
9448685117
commit
824cf7db1b
15
CHANGELOG
15
CHANGELOG
|
@ -1,3 +1,18 @@
|
||||||
|
ikiwiki (3.20190208) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
|
* po: Always filter .po files.
|
||||||
|
The po plugin in previous ikiwiki releases made the second and
|
||||||
|
subsequent filter call per (page, destpage) pair into a no-op,
|
||||||
|
apparently in an attempt to prevent *recursive* filtering (which as
|
||||||
|
far as we can tell can't happen anyway), with the undesired effect
|
||||||
|
of interpreting the raw .po file as page content (e.g. Markdown)
|
||||||
|
if it was inlined into the same page twice, which is apparently
|
||||||
|
something that tails.org does. Simplify this by deleting the code
|
||||||
|
that prevented repeated filtering. Thanks, intrigeri
|
||||||
|
(Closes: #911356)
|
||||||
|
|
||||||
|
-- Simon McVittie <smcv@debian.org> Sun, 24 Feb 2019 17:11:39 +0000
|
||||||
|
|
||||||
ikiwiki (3.20190207) upstream; urgency=medium
|
ikiwiki (3.20190207) upstream; urgency=medium
|
||||||
|
|
||||||
[ Amitai Schleier ]
|
[ Amitai Schleier ]
|
||||||
|
|
|
@ -51,7 +51,6 @@ sub import {
|
||||||
hook(type => "checkcontent", id => "po", call => \&checkcontent);
|
hook(type => "checkcontent", id => "po", call => \&checkcontent);
|
||||||
hook(type => "canremove", id => "po", call => \&canremove);
|
hook(type => "canremove", id => "po", call => \&canremove);
|
||||||
hook(type => "canrename", id => "po", call => \&canrename);
|
hook(type => "canrename", id => "po", call => \&canrename);
|
||||||
hook(type => "editcontent", id => "po", call => \&editcontent);
|
|
||||||
hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
|
hook(type => "formbuilder_setup", id => "po", call => \&formbuilder_setup, last => 1);
|
||||||
hook(type => "formbuilder", id => "po", call => \&formbuilder);
|
hook(type => "formbuilder", id => "po", call => \&formbuilder);
|
||||||
|
|
||||||
|
@ -303,9 +302,8 @@ sub filter (@) {
|
||||||
my $page = $params{page};
|
my $page = $params{page};
|
||||||
my $destpage = $params{destpage};
|
my $destpage = $params{destpage};
|
||||||
my $content = $params{content};
|
my $content = $params{content};
|
||||||
if (istranslation($page) && ! alreadyfiltered($page, $destpage)) {
|
if (istranslation($page)) {
|
||||||
$content = po_to_markup($page, $content);
|
$content = po_to_markup($page, $content);
|
||||||
setalreadyfiltered($page, $destpage);
|
|
||||||
}
|
}
|
||||||
return $content;
|
return $content;
|
||||||
}
|
}
|
||||||
|
@ -520,15 +518,6 @@ sub canrename (@) {
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
# As we're previewing or saving a page, the content may have
|
|
||||||
# changed, so tell the next filter() invocation it must not be lazy.
|
|
||||||
sub editcontent () {
|
|
||||||
my %params=@_;
|
|
||||||
|
|
||||||
unsetalreadyfiltered($params{page}, $params{page});
|
|
||||||
return $params{content};
|
|
||||||
}
|
|
||||||
|
|
||||||
sub formbuilder_setup (@) {
|
sub formbuilder_setup (@) {
|
||||||
my %params=@_;
|
my %params=@_;
|
||||||
my $form=$params{form};
|
my $form=$params{form};
|
||||||
|
@ -736,42 +725,6 @@ sub myisselflink ($$) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# ,----
|
|
||||||
# | Blackboxes for private data
|
|
||||||
# `----
|
|
||||||
|
|
||||||
{
|
|
||||||
my %filtered;
|
|
||||||
|
|
||||||
sub alreadyfiltered($$) {
|
|
||||||
my $page=shift;
|
|
||||||
my $destpage=shift;
|
|
||||||
|
|
||||||
return exists $filtered{$page}{$destpage}
|
|
||||||
&& $filtered{$page}{$destpage} eq 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub setalreadyfiltered($$) {
|
|
||||||
my $page=shift;
|
|
||||||
my $destpage=shift;
|
|
||||||
|
|
||||||
$filtered{$page}{$destpage}=1;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub unsetalreadyfiltered($$) {
|
|
||||||
my $page=shift;
|
|
||||||
my $destpage=shift;
|
|
||||||
|
|
||||||
if (exists $filtered{$page}{$destpage}) {
|
|
||||||
delete $filtered{$page}{$destpage};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub resetalreadyfiltered() {
|
|
||||||
undef %filtered;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# ,----
|
# ,----
|
||||||
# | Helper functions
|
# | Helper functions
|
||||||
# `----
|
# `----
|
||||||
|
@ -1146,7 +1099,6 @@ sub commit_and_refresh ($) {
|
||||||
IkiWiki::rcs_update();
|
IkiWiki::rcs_update();
|
||||||
}
|
}
|
||||||
# Reinitialize module's private variables.
|
# Reinitialize module's private variables.
|
||||||
resetalreadyfiltered();
|
|
||||||
resettranslationscache();
|
resettranslationscache();
|
||||||
flushmemoizecache();
|
flushmemoizecache();
|
||||||
# Trigger a wiki refresh.
|
# Trigger a wiki refresh.
|
||||||
|
|
|
@ -177,3 +177,6 @@ be resolved by renaming.
|
||||||
|
|
||||||
If it's valid to remove the `alreadyfiltered` mechanism, my
|
If it's valid to remove the `alreadyfiltered` mechanism, my
|
||||||
`wip/po-filter-every-time` branch does that. Please test?
|
`wip/po-filter-every-time` branch does that. Please test?
|
||||||
|
|
||||||
|
> intrigeri says [this change works as intended on tails.org](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911356#41),
|
||||||
|
> so I've applied it. [[done]] --[[smcv]]
|
||||||
|
|
38
t/po.t
38
t/po.t
|
@ -440,20 +440,6 @@ like($output{debian911356}, qr{
|
||||||
<p>After\sinlines</p>
|
<p>After\sinlines</p>
|
||||||
}sx);
|
}sx);
|
||||||
|
|
||||||
like($output{'debian911356.fr'}, qr{
|
|
||||||
<p>Avant\sla\spremière\sinline</p>
|
|
||||||
\s*
|
|
||||||
<p>Contenu\sfrançais</p>
|
|
||||||
\s*
|
|
||||||
<p>Entre\sles\sinlines</p>
|
|
||||||
\s*
|
|
||||||
.* # TODO: This paragraph gets mangled (Debian #911356)
|
|
||||||
\s*
|
|
||||||
<p>Après\sles\sinlines</p>
|
|
||||||
}sx);
|
|
||||||
|
|
||||||
TODO: {
|
|
||||||
local $TODO = "Debian bug #911356";
|
|
||||||
like($output{'debian911356.fr'}, qr{
|
like($output{'debian911356.fr'}, qr{
|
||||||
<p>Avant\sla\spremière\sinline</p>
|
<p>Avant\sla\spremière\sinline</p>
|
||||||
\s*
|
\s*
|
||||||
|
@ -465,7 +451,6 @@ like($output{'debian911356.fr'}, qr{
|
||||||
\s*
|
\s*
|
||||||
<p>Après\sles\sinlines</p>
|
<p>Après\sles\sinlines</p>
|
||||||
}sx);
|
}sx);
|
||||||
};
|
|
||||||
|
|
||||||
# Variation of Debian #911356 without using raw inlines.
|
# Variation of Debian #911356 without using raw inlines.
|
||||||
like($output{debian911356ish}, qr{
|
like($output{debian911356ish}, qr{
|
||||||
|
@ -496,28 +481,6 @@ like($output{debian911356ish}, qr{
|
||||||
<p>After\sinlines</p>
|
<p>After\sinlines</p>
|
||||||
}sx);
|
}sx);
|
||||||
|
|
||||||
like($output{'debian911356ish.fr'}, qr{
|
|
||||||
<p>Avant\sla\spremière\sinline</p>
|
|
||||||
\s*
|
|
||||||
<!--feedlinks-->
|
|
||||||
\s*
|
|
||||||
<div\sclass="inlinecontent">
|
|
||||||
\s*
|
|
||||||
<h6>debian911356-inlined\.fr</h6>
|
|
||||||
\s*
|
|
||||||
<p>Contenu\sfrançais</p>
|
|
||||||
\s*
|
|
||||||
</div><!--inlinecontent-->
|
|
||||||
\s*
|
|
||||||
<p>Entre\sles\sinlines</p>
|
|
||||||
\s*
|
|
||||||
.* # TODO: This paragraph gets mangled (Debian #911356)
|
|
||||||
\s*
|
|
||||||
<p>Après\sles\sinlines</p>
|
|
||||||
}sx);
|
|
||||||
|
|
||||||
TODO: {
|
|
||||||
local $TODO = "Debian bug #911356";
|
|
||||||
like($output{'debian911356ish.fr'}, qr{
|
like($output{'debian911356ish.fr'}, qr{
|
||||||
<p>Avant\sla\spremière\sinline</p>
|
<p>Avant\sla\spremière\sinline</p>
|
||||||
\s*
|
\s*
|
||||||
|
@ -545,6 +508,5 @@ like($output{'debian911356ish.fr'}, qr{
|
||||||
\s*
|
\s*
|
||||||
<p>Après\sles\sinlines</p>
|
<p>Après\sles\sinlines</p>
|
||||||
}sx);
|
}sx);
|
||||||
};
|
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue