[Jifty-commit] r3195 - in Template-Declare: t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sat May 5 21:22:37 EDT 2007


Author: ruz
Date: Sat May  5 21:22:36 2007
New Revision: 3195

Modified:
   Template-Declare/lib/Template/Declare/Tags.pm
   Template-Declare/t/utf8.t

Log:
* drop 'use bytes' as it actually breaks utf8 strings.

If we're in bytes mode and had a string with UTF-8 flag set
then after escaping we'll get a string without flag, but it
still would be valid UTF-8 and must have flag set. Effect
is not obviouse at this step, but later if you'll try to
concatenate the result with a flagged UTF-8 string then perl
"auto-upgrade" the result using 'latin1 -> UTF-8' transformation
applied to your valid UTF-8 string and you'll get corruption.

* tests


Modified: Template-Declare/lib/Template/Declare/Tags.pm
==============================================================================
--- Template-Declare/lib/Template/Declare/Tags.pm	(original)
+++ Template-Declare/lib/Template/Declare/Tags.pm	Sat May  5 21:22:36 2007
@@ -480,7 +480,6 @@
 }
 sub _escape_utf8 {
     my $val = shift;
-    use bytes;
     no warnings 'uninitialized';
     $val =~ s/&/&/g;
     $val =~ s/</&lt;/g;

Modified: Template-Declare/t/utf8.t
==============================================================================
--- Template-Declare/t/utf8.t	(original)
+++ Template-Declare/t/utf8.t	Sat May  5 21:22:36 2007
@@ -12,17 +12,20 @@
 my $str = "\x{442}\x{435}\x{441}\x{442}";
 
 template simple_outs => sub { outs("$str") };
-
 template double_outs => sub { outs("$str"); outs("$str") };
 
 template tag_outs => sub { p { outs("$str") } };
 template double_tag_outs => sub { p { outs("$str") } p { outs("$str") } };
 
+template attr => sub { p {{ title is "$str" }} };
+template attr_with_escape => sub { p {{ title is "<$str>" }} };
+
+
 Template::Declare->init(roots => ['Wifty::UI']);
 
 1;
 
-use Test::More tests => 8;
+use Test::More tests => 12;
 require "t/utils.pl";
 
 {
@@ -61,3 +64,19 @@
 }
 Template::Declare->buffer->clear;
 
+{
+    my $simple = (show('attr'));
+    ok($simple =~ m{^\s*<p\s+title="$str"\s*></p>\s*$}s);
+    # diag ($simple);
+    ok_lint($simple);
+}
+Template::Declare->buffer->clear;
+
+{
+    my $simple = (show('attr_with_escape'));
+    ok($simple =~ m{^\s*<p\s+title="&lt;$str&gt;"\s*></p>\s*$}s);
+    #diag ($simple);
+    ok_lint($simple);
+}
+Template::Declare->buffer->clear;
+


More information about the Jifty-commit mailing list