From c38c850469db06deae39db923e02372eda83cefc Mon Sep 17 00:00:00 2001 From: Hammat Wele Date: Fri, 6 Mar 2026 16:48:15 +0000 Subject: [PATCH] Bug 8937: Translation process removes CDATA in RSS XML During template translation, CDATA sections in RSS templates are not handled consistently. When parsing RSS content containing Template Toolkit directives inside CDATA blocks, the CDATA markers () are only preserved only for the tag. To reproduce 1. Install the other language (i used fr-CA here) 1.1. gulp po:update --lang fr-CA 1.2. /misc/translator/translate install fr-CA 2. open and compare files that contain <!CDATA in description example: ./koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt ./koha-tmpl/opac-tmpl/bootstrap/fr-CA/modules/opac-opensearch.tt 3. In the fr-CA file the description tag ==> the <![CDATA is removed 3. Apply the patch 4. Repeat step 1.2, 2 and 3 ==> the <![CDATA is not removed Signed-off-by: David Nind <david@davidnind.com> --- C4/TTParser.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/C4/TTParser.pm b/C4/TTParser.pm index f1556206a5..cc61fbfae9 100644 --- a/C4/TTParser.pm +++ b/C4/TTParser.pm @@ -52,7 +52,8 @@ sub peep_token { #signature build_tokens( self, filename) sub build_tokens { my ( $self, $filename ) = @_; - $self->{filename} = $filename; + $self->{filename} = $filename; + $self->{current_tag} = ''; $self->handler( start => "start", "self, line, tagname, attr, text" ) ; #signature is start( self, linenumber, tagname, hash of attributes, original text ) $self->handler( text => "text", "self, line, text, is_cdata" ) @@ -79,6 +80,10 @@ sub text { my $work = shift; # original text my $is_cdata = shift; + if ( $self->{current_tag} ne 'script' && $self->{current_tag} ne 'style' && $is_cdata ) { + $work = "<![CDATA[$work]]>"; + } + # If there is a split template toolkit tag if ( $work =~ m/^(?:(?!\[%).)*?%\]/s ) { my @strings = ($&); @@ -191,6 +196,8 @@ sub start { my $t = C4::TmplToken->new( $text, C4::TmplTokenType::TAG, $line, $self->{filename} ); my %attr; + $self->{current_tag} = $tag; + # tags seem to be uses in an 'interesting' way elsewhere.. for my $key (%$hash) { next unless defined $hash->{$key}; @@ -216,6 +223,8 @@ sub end { my $t = C4::TmplToken->new( $text, C4::TmplTokenType::TAG, $line, $self->{filename} ); my %attr; + $self->{current_tag} = ''; + # tags seem to be uses in an 'interesting' way elsewhere.. for my $key (%$hash) { next unless defined $hash->{$key}; -- 2.39.5