From e83cbdb302ab52d9fc0554b0c6e1759d8189ce98 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 15 Oct 2018 19:44:06 -0300 Subject: [PATCH] Bug 21576: Handle complex uri Only the first TT params in a href was taken into account. This also takes care to replace into href attributes only (for instance not title, etc.) --- t/lib/QA/TemplateFilters.pm | 221 ++++++++++++++++++++++---------------------- t/template_filters.t | 4 + 2 files changed, 114 insertions(+), 111 deletions(-) diff --git a/t/lib/QA/TemplateFilters.pm b/t/lib/QA/TemplateFilters.pm index 8e817ce013..f270388c19 100644 --- a/t/lib/QA/TemplateFilters.pm +++ b/t/lib/QA/TemplateFilters.pm @@ -68,6 +68,23 @@ sub _process_tt_content { $has_use_raw++ if $line =~ m{\[% USE raw %\]}; # Does [% Use raw %] exist? + my $e; + if ( $line =~ qr{(\s|\-|~)*) + (?[^%\-~]+) + (?(\s|\-|~)*) + %\]}gmxs + ) + { + ( $new_line, $e ) = process_tt_block($new_line, { %+, filter => 'uri' }); + push @errors, { line => $line, line_number => $line_number, error => $e } if $e; + } + } + # Loop on TT blocks while ( $line =~ m{ @@ -78,118 +95,10 @@ sub _process_tt_content { %\]}gmxs ) { - my $tt_block = $+{tt_block}; - my $pre_chomp = $+{pre_chomp}; - my $post_chomp = $+{post_chomp}; - - next if - # It's a TT directive, no filters needed - grep { $tt_block =~ $_ } @tt_directives - - # It is a comment - or $tt_block =~ m{^\#} - - # Already escaped with a special filter - # We could escape it but should be safe - or $tt_block =~ m{\s?\|\s?\$KohaDates\s?$} - or $tt_block =~ m{\s?\|\s?\$Price\s?$} - - # Already escaped correctly with raw - or $tt_block =~ m{\|\s?\$raw} - - # Assignment, maybe we should require to use SET (?) - or $tt_block =~ m{=} - - # Already has url or uri filter - or $tt_block =~ m{\|\s?ur(l|i)} - - # Specific for [% foo UNLESS bar %] - or $tt_block =~ m{^(?\S+)\s+UNLESS\s+(?\S+)} - ; - - $pre_chomp = - $pre_chomp - ? $pre_chomp =~ m|-| - ? q|- | - : $pre_chomp =~ m|~| - ? q|~ | - : q| | - : q| |; - $post_chomp = - $post_chomp - ? $post_chomp =~ m|-| - ? q| -| - : $post_chomp =~ m|~| - ? q| ~| - : q| | - : q| |; - - if ( - - # Use the uri filter - # If html filtered or not filtered - $new_line =~ qr{ - [% myuri %] [% myurl %] [% myurl %] +[% another_var %] +[% myuri | html %] [% myurl | html %] [% myurl | html %] +[% another_var | html %] +