View | Details | Raw Unified | Return to bug 22007
Collapse All | Expand All

(-)a/t/lib/QA/TemplateFilters.pm (-3 / +17 lines)
Lines 133-146 sub process_tt_block { Link Here
133
133
134
        # Already escaped with a special filter
134
        # Already escaped with a special filter
135
        # We could escape it but should be safe
135
        # We could escape it but should be safe
136
        or $tt_block =~ m{\s?\|\s?\$KohaDates\s?$}
136
        or $tt_block =~ m{\s?\|\s?\$KohaDates[^\|]*$}
137
        or $tt_block =~ m{\s?\|\s?\$Price\s?$}
138
137
139
        # Already escaped correctly with raw
138
        # Already escaped correctly with raw
140
        or $tt_block =~ m{\|\s?\$raw}
139
        or $tt_block =~ m{\|\s?\$raw}
141
140
142
        # Assignment, maybe we should require to use SET (?)
141
        # Assignment, maybe we should require to use SET (?)
143
        or $tt_block =~ m{=}
142
        or ( $tt_block =~ m{=} and not $tt_block =~ m{\s\|\s} )
144
143
145
        # Already has url or uri filter
144
        # Already has url or uri filter
146
        or $tt_block =~ m{\|\s?ur(l|i)}
145
        or $tt_block =~ m{\|\s?ur(l|i)}
Lines 166-171 sub process_tt_block { Link Here
166
            : q| |
165
            : q| |
167
      : q| |;
166
      : q| |;
168
167
168
    if (   $tt_block =~ m{\s?\|\s?\$KohaDates[^\|]*\|.*$}
169
    ) {
170
        $tt_block =~
171
          s/\s*\|\s*(uri|url|html)\s*$//;    # Could be another filter...
172
        $line =~ s{
173
            \[%
174
            \s*$pre_chomp\s*
175
            \Q$tt_block\E\s*\|\s*(uri|url|html)
176
            \s*$post_chomp\s*
177
            %\]
178
        }{[%$pre_chomp$tt_block$post_chomp%]}xms;
179
180
        return ( $line, 'extra_filter_not_needed' );
181
    }
182
169
    if (
183
    if (
170
        # Use the uri filter is needed
184
        # Use the uri filter is needed
171
        # If html filtered or not filtered
185
        # If html filtered or not filtered
(-)a/t/template_filters.t (-2 / +40 lines)
Lines 16-22 Link Here
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
16
# along with Koha; if not, see <http://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
use Test::More tests => 5;
19
use Test::More tests => 6;
20
use t::lib::QA::TemplateFilters;
20
use t::lib::QA::TemplateFilters;
21
21
22
subtest 'Asset must use raw' => sub {
22
subtest 'Asset must use raw' => sub {
Lines 260-262 INPUT Link Here
260
    @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
260
    @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
261
    is_deeply( \@missing_filters, [], 'html_entity is a valid filter for href' );
261
    is_deeply( \@missing_filters, [], 'html_entity is a valid filter for href' );
262
};
262
};
263
- 
263
264
subtest 'Do not escape KohaDates output' => sub {
265
    plan tests => 2;
266
    my $input = <<INPUT;
267
[% var | \$KohaDates %]
268
[% var | \$KohaDates with_hours => 1 %]
269
[% var | \$KohaDates | html %]
270
[% var | \$KohaDates with_hours => 1 | html %]
271
INPUT
272
273
    my $expected = <<EXPECTED;
274
[% var | \$KohaDates %]
275
[% var | \$KohaDates with_hours => 1 %]
276
[% var | \$KohaDates %]
277
[% var | \$KohaDates with_hours => 1 %]
278
EXPECTED
279
280
    my $new_content = t::lib::QA::TemplateFilters::fix_filters($input);
281
    is( $new_content . "\n", $expected, );
282
283
284
    my @missing_filters = t::lib::QA::TemplateFilters::missing_filters($input);
285
    is_deeply(
286
        \@missing_filters,
287
        [
288
            {
289
                error       => "extra_filter_not_needed",
290
                line        => "[% var | \$KohaDates | html %]",
291
                line_number => 3,
292
            },
293
            {
294
                error       => "extra_filter_not_needed",
295
                line        => "[% var | \$KohaDates with_hours => 1 | html %]",
296
                line_number => 4,
297
            }
298
        ]
299
    );
300
301
};

Return to bug 22007