Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Commit

Permalink
Improved handling of JSData in Templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgruner committed Sep 18, 2018
1 parent bd083b5 commit 40bbcc2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#6.0.12 2018-??-??
- 2018-09-18 Improved handling of JSData in Templates.

#6.0.11 2018-09-21
- 2018-09-13 Updated translations, thanks to all translators.
Expand Down
5 changes: 5 additions & 0 deletions Kernel/Output/Template/Document.pm
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ sub _InstallOTRSExtensions {
Data => \%Data,
SortKeys => 1,
);

# Escape closing script tags in the JSON content as they will confuse the
# browser's parser.
$JSONString =~ s{</script}{<\\/script}smxg;

$output .= "Core.Config.AddConfig($JSONString);\n";
}
delete $context->{LayoutObject}->{_JSData};
Expand Down
11 changes: 10 additions & 1 deletion scripts/test/Layout/Template/Render.t
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,21 @@ console.log(22);
},
Result => '',
},
{
Name => 'JSData 3 with AddJSData()',
Template => '',
AddJSData => {
Key => 'JS.String',
Value => { String => '</script></script>' }
},
Result => '',
},
{
Name => 'JSDataInsert',
Template => '
[% PROCESS "JSDataInsert" -%]',
Result => '
Core.Config.AddConfig({"Config.Test":123,"Config.Test2":[1,2,{"test":"test"}],"Perl.Code":{"Perl":"Data"}});
Core.Config.AddConfig({"Config.Test":123,"Config.Test2":[1,2,{"test":"test"}],"JS.String":{"String":"<\/script><\/script>"},"Perl.Code":{"Perl":"Data"}});
',
},
{
Expand Down

0 comments on commit 40bbcc2

Please sign in to comment.