Subject: | Inconsistent utf8 handling... |
Date: | Thu, 28 May 2015 17:27:08 +0200 |
To: | bug-EJS-Template [...] rt.cpan.org |
From: | Jozef Mojzis <jozef.mojzis [...] gmail.com> |
Strange unicode problems. Used engine: "JE".
Try the following template "test.ejs" (utf8 file).
Show quoted text
--- cut here ---
<%
var intempl = "čšňž";
var joined = intempl + fromperl;
%>
Length of the intempl: <%= intempl.length %>
Length of the fromperl: <%= fromperl.length %>
Length of the joined: <%= joined.length %>
<% for (var i = 0; i < joined.length; i++) { %>
at position <%= i %> =<%= joined.charAt(i) %>=
<% } %>
--- cut here ---
and run it with the following script (also utf8).
use 5.014; #<-- use strict; use feature 'unicode_strings';
use warnings;
use utf8; #this source contains utf8 encoded characters
use Path::Tiny;
use EJS::Template;
binmode STDOUT,':utf8';
#slurp utf8 file
my $input = path("test.ejs")->slurp_utf8;
say "-- [ input ]", "-"x40;
say $input;
#parse and print the code
my $code;
EJS::Template->parse(\$input, \$code);
say "-- [ code ]", "-"x40;
say $code;
#run the JS
my $out;
EJS::Template->execute(\$code, {fromperl => 'čšňž'}, \$out);
say "-- [ output ]", "-"x40;
say $out;
In the rendered output is
- correctly handled the variable declared in the javascript (the variable intempl - e.g. the JE-engine knows how to handle wide chars)
- but the variable coming from perl isn't handled correctly (the passing method is probably bugged somewhat).
Ps: both variables (intempl and fromperl) (should) contains:
U+0010D č LATIN SMALL LETTER C WITH CARON
U+00161 š LATIN SMALL LETTER S WITH CARON
U+00148 ň LATIN SMALL LETTER N WITH CARON
U+0017E ž LATIN SMALL LETTER Z WITH CARON