Bug 12076: better detect an untranslatable template construct
authorGalen Charlton <gmc@esilibrary.com>
Fri, 11 Apr 2014 18:49:07 +0000 (18:49 +0000)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 13 Aug 2014 14:01:11 +0000 (10:01 -0400)
Per bug 6458, template constructs of the form

<li [% IF (foo) %]selected="selected"[% END %]...

are forbidden as they can cause problems with translated templates.
However, the tt_valid.t test currently doesn't catch the variation
where '-' is used to suppress extra whitespace:

<li [%- IF (foo) -%]selected="selected"[%- END -%]...

This patch corrects the issue.

To test:

[1] Temporarily add the following line to a template file:

<li [%- IF a -%]a="a"[%- END -%] />

[2] Run prove -v xt/tt_valid.t.  Note that no error is reported.
[3] Apply the patch, and rerun the tt_valid.t test.  This time,
    an error should be reported.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>

Works well, detects the forbidden pattern
No koha-qa errors.

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Works as described, passes all tests and QA script.

Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit 9a7eedce78af128772a36b5a16416fdad1a16fcc)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit a7b28d19a71f16ebad3805139e7f82f268d77c5c)

xt/tt_valid.t

index f71085e..e33b760 100755 (executable)
@@ -38,7 +38,7 @@ my @files_with_directive_in_tag = do {
         while ( my $token = $parser->next_token ) {
             my $attr = $token->{_attr};
             next unless $attr;
-            push @lines, $token->{_lc} if $attr->{'[%'};
+            push @lines, $token->{_lc} if $attr->{'[%'} or $attr->{'[%-'};
         }
         ($dir) = $dir =~ /koha-tmpl\/(.*)$/;
         push @files, { name => "$dir/$name", lines => \@lines } if @lines;