Commit 1735f6f53ca19f99c6e9e39496c486af323ba6a8 started to escape all
author=?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Fri, 8 Nov 2013 01:17:08 +0000 (02:17 +0100)
committerJames E Keenan <jkeenan@cpan.org>
Fri, 8 Nov 2013 01:17:08 +0000 (02:17 +0100)
back-slashes which breaks case when lexicon translations contain substition
and literals with eval-non-safe characters. E.g.  these translations:

"[_1]foo\\n\n" => "[_1]bar\\n\n",
'[_1]foo\n' => '[_1]aÄ\9ba\n',

got doubled back-slashes on the maketext() output.

This patch de-escapes escaped backslashes if the literal is compiled as
function argument.

Fixes RT #120457.

MANIFEST
dist/Locale-Maketext/lib/Locale/Maketext.pm
dist/Locale-Maketext/t/91_backslash.t [new file with mode: 0644]

index 5494384..3f0400a 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -3140,6 +3140,7 @@ dist/Locale-Maketext/t/50_super.t                 See if Locale::Maketext works
 dist/Locale-Maketext/t/60_super.t                      See if Locale::Maketext works
 dist/Locale-Maketext/t/70_fail_auto.t                  See if Locale::Maketext works
 dist/Locale-Maketext/t/90_utf8.t                       See if Locale::Maketext works
+dist/Locale-Maketext/t/91_backslash.t                  See if Locale::Maketext works
 dist/Math-BigInt-FastCalc/FastCalc.xs  Math::BigInt::FastCalc extension
 dist/Math-BigInt-FastCalc/lib/Math/BigInt/FastCalc.pm  Math::BigInt::FastCalc extension
 dist/Math-BigInt-FastCalc/t/bigintfc.t Math::BigInt::FastCalc extension
index a21d679..c2bd723 100644 (file)
@@ -27,7 +27,7 @@ BEGIN {
 }
 
 
-$VERSION = '1.24';
+$VERSION = '1.25';
 @ISA = ();
 
 $MATCH_SUPERS = 1;
@@ -570,6 +570,7 @@ sub _compile {
                             $c[-1] = ''; # reuse this slot
                         }
                         else {
+                            $c[-1] =~ s/\\\\/\\/g;
                             push @code, ' $c[' . $#c . "],\n";
                             push @c, ''; # new chunk
                         }
diff --git a/dist/Locale-Maketext/t/91_backslash.t b/dist/Locale-Maketext/t/91_backslash.t
new file mode 100644 (file)
index 0000000..f96edd1
--- /dev/null
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -Tw
+
+use strict;
+use Test::More tests => 6;
+
+BEGIN {
+    use_ok( 'Locale::Maketext' );
+}
+
+use utf8;
+
+{
+    package My::Localize;
+    our @ISA = ('Locale::Maketext');
+}
+{
+    package My::Localize::cs_cz;
+    our @ISA = ('My::Localize');
+    our %Lexicon = (
+        '[_1]foo1\n' => '[_1]bar\n',
+        '[_1]foo2\n' => '[_1]běr\n',
+        'foo2\n' => 'aěa\n',
+        "[_1]foo\\n\n" => "[_1]bar\\n\n",
+    );
+    keys %Lexicon; # dodges the 'used only once' warning
+}
+
+my $lh = My::Localize->get_handle('cs_cz');
+isa_ok( $lh, 'My::Localize::cs_cz' );
+is( $lh->maketext('[_1]foo1\n', 'arg'), 'argbar\n', 'Safe parameterized' );
+is( $lh->maketext('[_1]foo2\n', 'arg'), 'argběr\n', 'Unicode parameterized' );
+is( $lh->maketext('foo2\n'), 'aěa\n', 'Unicode literal' );
+is( $lh->maketext("[_1]foo\\n\n", 'arg'), "argbar\\n\n", 'new line parameterized' );