Re: [perl #39126] possible memory related bug when using sprintf with an utf-8 encode...
[p5sagit/p5-mst-13.2.git] / t / op / sprintf2.t
index 7544705..81450ce 100644 (file)
@@ -6,7 +6,7 @@ BEGIN {
     require './test.pl';
 }   
 
-plan tests => 275;
+plan tests => 280;
 
 is(
     sprintf("%.40g ",0.01),
@@ -18,13 +18,14 @@ is(
     sprintf("%.40f", 0.01)." ",
     q(the sprintf "%.<number>f" optimization)
 );
-{
-       chop(my $utf8_format = "%-3s\x{100}");
-       is(
-               sprintf($utf8_format, "\xe4"),
-               "\xe4  ",
-               q(width calculation under utf8 upgrade)
-       );
+
+# cases of $i > 1 are against [perl #39126]
+for my $i (1, 5, 10, 20, 50, 100) {
+    chop(my $utf8_format = "%-*s\x{100}");
+    my $string = "\xB4"x$i;        # latin1 ACUTE or ebcdic COPYRIGHT
+    my $expect = $string."  "x$i;  # followed by 2*$i spaces
+    is(sprintf($utf8_format, 3*$i, $string), $expect,
+       "width calculation under utf8 upgrade, length=$i");
 }
 
 # Used to mangle PL_sv_undef