From 272c1b1b8e5462936c26d73f8f668292571f811a Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 6 Jul 2012 17:29:17 +1200 Subject: [PATCH] Encode UTF-8 strings before we print out out. --- ChangeLog | 3 +++ bin/mythtv-status | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ce514f7..4154c85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2012-07-06 Andrew Ruthven + Correctly handle UTF-8 in the output from MythTV. + 2012-06-14 Andrew Ruthven Setting $0 stopped --help and -? from working, fix that. diff --git a/bin/mythtv-status b/bin/mythtv-status index f1e458f..c63394d 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -27,6 +27,7 @@ use MIME::Entity; use Pod::Usage; use Config::Auto; use Sys::SigAction qw/timeout_call/; +use Encode; # Try and load a config file first, and then allow the command line # to over ride what is in the config file. @@ -85,7 +86,7 @@ my @size_thresholds = ( my $return_code_only = 0; -my $VERSION = '0.10.2'; +my $VERSION = '0.10.3'; # Some display blocks are disabled by default: $c->{'display'}{'Shows due to Auto Expire'} = 0; @@ -621,6 +622,9 @@ if (scalar(@oneliners) > 0) { if ($return_code_only) { exit $exit_value; } elsif (scalar(@{ $c->{'email'} }) == 0) { + if ($charset =~ /utf(-)?8/i) { + $output = encode('UTF-8', $output); + } print "\n$output"; } else { if ((! $c->{'email_only_on_alert'}) || @@ -1095,8 +1099,12 @@ sub xml_fetch { die "Sorry, failed to fetch $url: " . $response->status_line . "\n" unless $response->is_success; + my $content = $response->decoded_content; + if ($response->header('Content-Type') =~ /utf(-)?8/i) { + $content = encode('UTF-8', $content); + } print $response->header('Content-Type') . "\n"; - print $response->decoded_content . "\n"; + print $content . "\n"; exit 0; } -- 2.30.2