Re: Question and possibly bugs about string encoding in gtk-perl



[ 2nd try ]

On Wednesday, 14 December 2016 10:54:16 CET Boyuan Yang wrote:
The original messy output, as indicated in screenshot in the Ubuntu bug,
looks  like treating a latin-1-encoded binary data as UTF-8-encoded data
and showing them anyway. 

In more details, the problematic code boils down to:
 
 my $wnck_screen = Gnome2::Wnck::Screen->get_default;
 my $win= $wnck_screen->get_windows_stacked; # Gnome2::Wnck object
 my $name = $win->get_name;
 my $window_item = Gtk2::ImageMenuItem->new_with_label( $name );

$name contains window name apparently in octet format instead of an utf8 
string. As a consequence, the list of windows shown by shutter contains 
mojibake. 

The hacky patch proposed (by me) is using
Encode::_utf8_on() to turn on the internal flag for string and mark it as
UTF-8.

And I'm worried that shutter may crash if used in a non-utf8 environment.

After some experimentation, I've come up with a safer solution:

 use 5.12.0;
 use Encode::Locale;
 use Encode qw/decode/;
 # ...
 my $name = decode( 'locale' , $win->get_name);

This works in utf8 locale and is safer than turning utf8 flag on.

That said, shouldn't this decoding work be done in Gnome2::Wnck ?

All the best

-- 
 https://github.com/dod38fr/   -o- http://search.cpan.org/~ddumont/
http://ddumont.wordpress.com/  -o-   irc: dod at irc.debian.org


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]