Skip Menu |

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 27277
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: BORISZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: from_to does not honor the check while decoding
Hi, I used from_to to convert partly malformed data. But from_to ignores CHECK while decoding. here is a example and a attached patch to fix my issue. t/from_to.t is one test richer. # malformed utf8 my $t = "\xdf"; from_to( $t, utf8 => 'utf8', Encode::FB_PERLQQ ); -- Boris
Subject: Encode.patch
diff -Nur a/Encode-2.21/Encode.pm b/Encode-2.21/Encode.pm --- a/Encode-2.21/Encode.pm 2007-05-12 08:42:32.000000000 +0200 +++ b/Encode-2.21/Encode.pm 2007-05-24 17:40:25.000000000 +0200 @@ -179,7 +179,7 @@ require Carp; Carp::croak("Unknown encoding '$to'"); } - my $uni = $f->decode($string); + my $uni = $f->decode( $string, $check ); $_[0] = $string = $t->encode( $uni, $check ); return undef if ( $check && length($uni) ); return defined( $_[0] ) ? length($string) : undef; diff -Nur a/Encode-2.21/t/from_to.t b/Encode-2.21/t/from_to.t --- a/Encode-2.21/t/from_to.t 2007-05-12 08:42:39.000000000 +0200 +++ b/Encode-2.21/t/from_to.t 2007-05-24 18:28:43.000000000 +0200 @@ -1,6 +1,6 @@ # $Id: from_to.t,v 1.1 2006/01/15 15:06:36 dankogai Exp $ use strict; -use Test::More tests => 3; +use Test::More tests => 4; use Encode qw(encode from_to); my $foo = encode("utf-8", "\x{5abe}"); @@ -10,3 +10,7 @@ my $bar = encode("latin-1", "\x{5abe}", Encode::FB_HTMLCREF); is $bar, '媾'; + +my $baz = "\x{df}"; +from_to($baz, "utf8" => "utf8", Encode::FB_PERLQQ); +is $baz, '\\xDF';
BORISZ, That's deliberate. we DO NOT want from_to() to do tasks that requires minute controls. For those cases, use encode($to, decode($from, $data, $fallback_from), $fallback_to) Thank you for your report and patch, though. Dan the Encode Maintainer On Thu May 24 12:33:27 2007, BORISZ wrote: Show quoted text
> Hi, > > I used from_to to convert partly malformed data. But from_to ignores > CHECK while decoding. > > here is a example and a attached patch to fix my issue. t/from_to.t is > one test richer. > > # malformed utf8 > my $t = "\xdf"; > from_to( $t, utf8 => 'utf8', Encode::FB_PERLQQ );