Subject: | encode(..., Encode::LEAVE_SRC) does not work |
There is code in the XS implementation that tries to
make specifying Encode::LEAVE_SRC in CHECK to work, but
the perl wrapper destroys the attempt. The attached
patch fixes this problem.
BTW, shouldn't FB_PERLQQ, FB_HTMLCREF, FB_XMLCREF all
imply LEAVE_SRC? That seems more logial.
Demo:
bash-2.05b$ perl -MEncode -le 'print decode("utf8", "foo",
Encode::FB_PERLQQ)'
Modification of a read-only value attempted
at /opt/perl/ap811-a118878/lib/5.8.6/i686-linux-thread-multi/Encode.pm
line 167.
bash-2.05b$ perl -MEncode -le 'print decode("utf8", "foo",
Encode::FB_PERLQQ | Encode::LEAVE_SRC)'
Modification of a read-only value attempted
at /opt/perl/ap811-a118878/lib/5.8.6/i686-linux-thread-multi/Encode.pm
line 167.
==== //depot/users/gisle/hacks/Encode/Encode.pm#3 - /home/gisle/hacks/Encode/Encode.pm ====
Index: users/gisle/hacks/Encode/Encode.pm
--- users/gisle/hacks/Encode/Encode.pm.~1~ Sat Dec 4 12:00:49 2004
+++ users/gisle/hacks/Encode/Encode.pm Sat Dec 4 12:00:49 2004
@@ -148,7 +148,7 @@
Carp::croak("Unknown encoding '$name'");
}
my $octets = $enc->encode($string,$check);
- $_[1] = $string if $check;
+ $_[1] = $string if $check && !($check & Encode::LEAVE_SRC());
return $octets;
}
@@ -164,7 +164,7 @@
Carp::croak("Unknown encoding '$name'");
}
my $string = $enc->decode($octets,$check);
- $_[1] = $octets if $check;
+ $_[1] = $octets if $check && !($check & Encode::LEAVE_SRC());
return $string;
}
End of Patch.