unicode - Create an invalid UTF8 perl string? -


what's way create perl string utf8 flag set contains invalid utf8 byte sequence?

is there way set utf8 flag on perl string without performing native encoding utf-x translation (for instance, happens when call utf8::upgrade)?

i need track down possible bug in dbi driver.

that's encode's _utf8_on does.

use encode qw( _utf8_on );  $s = "abc\xc0def";  # string use raw buffer content. utf8::downgrade($s);   # make sure each char stored byte. _utf8_on($s);          # set utf8 flag. 

(never use _utf8_on except when want generate bad scalar.)

you can view damage using

use devel::peek qw( dump ); dump($s); 

output:

sv = pv(0x24899c) @ 0x4a9294   refcnt = 1   flags = (padmy,pok,ppok,utf8)   pv = 0x24ab04 "abc\300def"\0malformed utf-8 character (unexpected non-continuation byte 0x64, after start byte 0xc0) in subroutine entry @ script.pl line 9.  [utf8 "abc\x{0}ef"]   cur = 7   len = 12 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -