Closed p5pRT closed 12 years ago
When using Encode I was unpleasantly surprised by this:
perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK); print "a=\<$a>\n"' a=\<>
So encode() destroys its argument. As far as I see this possibility is nowhere explicitely documented in the Encode docs\, certainly not in the section about the encode() function.
Later on in the section "Handling Malformed Data" there is this table though:
FB_DEFAULT FB_CROAK FB_QUIET FB_WARN FB_PERLQQ DIE_ON_ERR 0x0001 X WARN_ON_ERR 0x0002 X RETURN_ON_ERR 0x0004 X X LEAVE_SRC 0x0008 PERLQQ 0x0100 X HTMLCREF 0x0200 XMLCREF 0x0400
While the meaning of LEAVE_SRC is nowhere documented\, one could guess it controls this behaviour\, and indeed:
perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK | Encode::LEAVE_SRC); print "a=\<$a>\n"'
a=\
However\, from that table I'd also conclude that e.g. FB_DEFAULT should destroy its argument\, however:
perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_DEFAULT); print "a=\<$a>\n"'
a=\
I think this pretty important behaviour needs documentation and the flags table should be made right
On Sun Apr 10 06:59:44 2005\, perl-5.8.0@ton.iguana.be wrote:
When using Encode I was unpleasantly surprised by this:
perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK); print "a=\<$a>\n"' a=\<>
So encode() destroys its argument.
More precisely\, it destroys its argument when Encode::FB_CROAK is provided as the third argument to encode().
###
$ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a); print "a=\<$a>\n"'
a=\
$ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_DEFAULT);
print "a=\<$a>\n"'
a=\
$ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK); print "a=\<$a>\n"' a=\<> ###
The RT System itself - Status changed from 'new' to 'open'
On Sat\, Nov 19\, 2011 at 12:51 PM\, James E Keenan via RT \< perlbug-followup@perl.org> wrote:
On Sun Apr 10 06:59:44 2005\, perl-5.8.0@ton.iguana.be wrote:
When using Encode I was unpleasantly surprised by this:
perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK); print "a=\<$a>\n"' a=\<>
So encode() destroys its argument.
More precisely\, it destroys its argument when Encode::FB_CROAK is provided as the third argument to encode().
### $ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a); print "a=\<$a>\n"' a=\
$ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_DEFAULT); print "a=\<$a>\n"' a=\
$ perl -MEncode -wle '$a="abcd"; encode("utf8"\, $a\, Encode::FB_CROAK); print "a=\<$a>\n"' a=\<> ###
This is actually in the docs though; See the part about Encode::LEAVE_SRC: "If the Encode::LEAVE_SRC bit is not set\, but CHECK is\, then the second argument to encode() or decode() may be assigned to by the functions. If you're not interested in this\, then bitwise-or the bitmask with it."
So this isn't a bug.
@cpansprout - Status changed from 'open' to 'rejected'
Migrated from rt.perl.org#34905 (status was 'rejected')
Searchable as RT34905$