From 1dbea5dd2c5c98b53dbc88493b97d6e0c419c244 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.) Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- 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 60b2d5debf..0a3fa44685 100644 --- a/t/lib/QA/TemplateFilters.pm +++ b/t/lib/QA/TemplateFilters.pm @@ -69,6 +69,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{ @@ -79,118 +96,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 %] +