From 0a0e8f0d6b4818648504e51b379a81781999437e Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 19 Feb 2012 23:22:45 -0500 Subject: [PATCH] Bug - UTF8 - Fixed bug in the handling of UTF8 JSON data from holidata.net, when update-holidays.pl when decoding and writing files. --- ChangeLog | 2 ++ scripts/add-ons/update-holidays.pl | 14 ++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1e1722d66..2d492ee1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -270,6 +270,8 @@ + Fixed problem with non-UTC defaults for "TZ" (thanks to Owen Clarke). + Removed use of Lua API call that is deprecated in 5.1 and removed from 5.2 (thanks to Michal Vyskocil). + + Fixed problem where update-holidays.pl did not properly handle UTF8 JSON + data. ------ old releases ------------------------------ diff --git a/scripts/add-ons/update-holidays.pl b/scripts/add-ons/update-holidays.pl index 071ec80d3..b574c1106 100755 --- a/scripts/add-ons/update-holidays.pl +++ b/scripts/add-ons/update-holidays.pl @@ -45,6 +45,13 @@ if ($@) exit 1; } +eval "use Encode"; +if ($@) +{ + print "Error: You need to install the Encode Perl module.\n"; + exit 1; +} + # Command line options, argument validation. my $help; my $locale; @@ -147,8 +154,8 @@ print "\n", # Without data, cannot proceed. my $data; -$data .= $data_current if defined $data_current; -$data .= $data_next if defined $data_next; +$data .= decode ('utf-8', $data_current) if defined $data_current; +$data .= decode ('utf-8', $data_next) if defined $data_next; exit (1) if !defined $data || $data eq ''; # Filter the holidays according to @regions. @@ -170,8 +177,7 @@ for my $holiday (split /\n/ms, $data) } # Overwrite the file. -if (open my $fh, '>', $file) -#if (open my $fh, '>:encoding(UTF-8)', $file) +if (open my $fh, '>:utf8', $file) { print $fh "# International Holiday Data provided by Holidata.net\n",