Don't fold constants in sprintf() if locales are used
authorNiko Tyni <ntyni@debian.org>
Wed, 27 Oct 2010 07:56:24 +0000 (10:56 +0300)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 27 Oct 2010 12:52:22 +0000 (05:52 -0700)
Commit c427f4d2d4575fbc8a5190932fe321136c7597b3 in 5.10.1 made sprintf()
ignore LC_NUMERIC for numeric constants.

op.c
t/run/locale.t

diff --git a/op.c b/op.c
index 1502628..ce9c220 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2606,6 +2606,7 @@ S_fold_constants(pTHX_ register OP *o)
     case OP_SLE:
     case OP_SGE:
     case OP_SCMP:
+    case OP_SPRINTF:
        /* XXX what about the numeric ops? */
        if (PL_hints & HINT_LOCALE)
            goto nope;
index 483123f..2f7306b 100644 (file)
@@ -128,6 +128,19 @@ EOF
            "too late to ignore the locale at write() time");
         }
     }
+
+    for ($different) {
+       local $ENV{LC_NUMERIC} = $_;
+       local $ENV{LC_ALL}; # so it never overrides LC_NUMERIC
+       fresh_perl_is(<<'EOF', "$difference "x4, {},
+           use locale;
+           use POSIX qw(locale_h);
+           setlocale(LC_NUMERIC, "");
+           my $in = 4.2;
+           printf("%g %g %s %s ", $in, 4.2, sprintf("%g", $in), sprintf("%g", 4.2));
+EOF
+       "sprintf() and printf() look at LC_NUMERIC regardless of constant folding");
+    }
 } # SKIP
 
-sub last { 6 }
+sub last { 7 }