Add a patch tag
[ikiwiki.git] / doc / bugs / cutpaste.pm:_missing_filter_call.mdwn
1 Consider this:
2
3     $ wget http://schwinge.homeip.net/~thomas/tmp/cutpaste_filter.tar.bz2
4     $ wget http://schwinge.homeip.net/~thomas/tmp/cutpaste_filter.patch
5     
6     $ tar -xj < cutpaste_filter.tar.bz2
7     $ cd cutpaste_filter/
8     $ ./render_locally
9     $ find "$PWD".rendered/ -type f -print0 | xargs -0 grep -H -E 'FOO|BAR'
10     [notice one FOO in there]
11     $ rm -rf .ikiwiki "$PWD".rendered
12     
13     $ cp /usr/share/perl5/IkiWiki/Plugin/cutpaste.pm .library/IkiWiki/Plugin/
14     $ patch -p0 < ../cutpaste_filter.patch
15     $ ./render_locally
16     $ find "$PWD".rendered/ -type f -print0 | xargs -0 grep -H -E 'FOO|BAR'
17     [correct; notice no more FOO]
18
19 I guess this needs a general audit -- there are other places where `preprocess`
20 is being doing without `filter`ing first, for example in the same file, `copy`
21 function.
22
23 --[[tschwinge]]
24
25 > So, in English, page text inside a cut directive will not be filtered.
26 > Because the cut directive takes the text during the scan pass, before
27 > filtering happens.
28
29 > Commit 192ce7a238af9021b0fd6dd571f22409af81ebaf and
30 > [[bugs/po_vs_templates]] has to do with this.
31 > There I decided that filter hooks should *only* act on the complete
32 > text of a page. 
33
34 > I also suggested that anything that wants to reliably
35 > s/FOO/BAR/ should probably use a sanitize hook, not a filter hook.
36 > I think that would make sense in this example.
37
38 > I don't see any way to make cut text be filtered while satisfying these
39 > constraints, without removing cutpaste's ability to have forward pastes
40 > of text cut laster in the page. (That does seems like an increasingly
41 > bad idea..) --[[Joey]]
42
43 > > OK -- so the FOO/BAR thing was only a very stripped-down example, of
44 > > course, and the real thing is being observed with the
45 > > *[[plugins/contrib/getfield]]* plugin.  This one needs to run *before*
46 > > `preprocess`ing, for its `{{$page#field}}` syntax is (a) meant to be usable
47 > > inside ikiwiki directives, and (b) the field values are meant to still be
48 > > `preprocess`ed before being embedded.  That's why it's using the `filter`
49 > > hook instead of `sanitize`.
50
51 > > Would adding another kind of hook be a way to fix this?  My idea is that
52 > > *cut* (and others) would then take their data not during `scan`ning, but
53 > > *after* `filter`ing.
54
55 > > --[[tschwinge]]