From 9ed284beecbf493c7e963b5a65d8495487005a94 Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Tue, 1 Apr 2008 14:42:20 +0000 Subject: [PATCH] use UTF8 JSON encoding and decoding universally fixed: Import/Export of packages with international text is broken --- docs/changelog/7.x.x.txt | 2 ++ lib/Spectre/Admin.pm | 2 +- lib/Spectre/Cron.pm | 4 ++-- lib/Spectre/Workflow.pm | 10 +++++----- lib/WebGUI/Asset/File/GalleryFile/Photo.pm | 6 +++--- lib/WebGUI/Asset/Wobject/Calendar.pm | 4 ++-- lib/WebGUI/Asset/Wobject/EventManagementSystem.pm | 4 ++-- lib/WebGUI/AssetPackage.pm | 4 ++-- lib/WebGUI/Commerce/Transaction.pm | 6 +++--- lib/WebGUI/Operation/Spectre.pm | 6 +++--- lib/WebGUI/Operation/Workflow.pm | 6 +++--- lib/WebGUI/Session/ErrorHandler.pm | 2 +- lib/WebGUI/Workflow/Activity/CalendarUpdateFeeds.pm | 10 +++++----- lib/WebGUI/Workflow/Activity/GetSyndicatedContent.pm | 6 +++--- lib/WebGUI/Workflow/Cron.pm | 4 ++-- lib/WebGUI/Workflow/Instance.pm | 6 +++--- 16 files changed, 42 insertions(+), 40 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index a441dc0b6..464ce2bfb 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -16,6 +16,8 @@ - fixed: changing style template with edit branch creates new revisions of assets that have no style template - fixed: Wiki attachments uploaded by non-Content Managers deleted by maintenance workflow - fixed: Non-Content managers unable to paste assets even with edit privaledges + - use UTF8 JSON encoding and decoding universally + - fixed: Import/Export of packages with international text is broken 7.5.8 - moved Gallery utility methods to WebGUI::Utility::Gallery diff --git a/lib/Spectre/Admin.pm b/lib/Spectre/Admin.pm index fbe10f8b9..c7a55cc27 100644 --- a/lib/Spectre/Admin.pm +++ b/lib/Spectre/Admin.pm @@ -152,7 +152,7 @@ sub loadSiteData { } else { my $siteData = {}; - eval { $siteData = JSON::from_json($response->content); }; + eval { $siteData = JSON::decode_json($response->content); }; if ($@) { $self->error("Couldn't fetch Spectre configuration data for $key : $@"); } diff --git a/lib/Spectre/Cron.pm b/lib/Spectre/Cron.pm index 309ab0a0c..cb64cc56b 100644 --- a/lib/Spectre/Cron.pm +++ b/lib/Spectre/Cron.pm @@ -19,7 +19,7 @@ use DateTime; use HTTP::Request::Common; use HTTP::Cookies; use POE qw(Component::Client::HTTP); -use JSON qw/ to_json /; +use JSON qw/ encode_json /; #------------------------------------------------------------------- @@ -337,7 +337,7 @@ sub getJsonStatus { next unless $self->{_jobs}->{$key}->{sitename} eq $sitename; $data{$key} = $self->{_jobs}->{$key}; } - $kernel->call(IKC => post => $rsvp, to_json(\%data)); + $kernel->call(IKC => post => $rsvp, encode_json(\%data)); } diff --git a/lib/Spectre/Workflow.pm b/lib/Spectre/Workflow.pm index 77c92838e..6abf16812 100644 --- a/lib/Spectre/Workflow.pm +++ b/lib/Spectre/Workflow.pm @@ -20,7 +20,7 @@ use HTTP::Cookies; use POE qw(Component::Client::HTTP); use POE::Queue::Array; use Tie::IxHash; -use JSON qw/ to_json /; +use JSON qw/ encode_json /; #------------------------------------------------------------------- @@ -223,7 +223,7 @@ sub editWorkflowPriority { if ($ackPriority != $newPriority) { # return an error my $error = 'edit priority setting error'; - $kernel->call(IKC=>post=>$rsvp, to_json({message => $error})); + $kernel->call(IKC=>post=>$rsvp, encode_json({message => $error})); } $found = 1; last; @@ -232,11 +232,11 @@ sub editWorkflowPriority { if (! $found) { # return an error message my $error = 'edit priority instance not found error'; - $kernel->call(IKC=>post=>$rsvp, to_json({message => $error})); + $kernel->call(IKC=>post=>$rsvp, encode_json({message => $error})); } else { # return success message - $kernel->call(IKC=>post=>$rsvp, to_json({message => 'edit priority success'})); + $kernel->call(IKC=>post=>$rsvp, encode_json({message => 'edit priority success'})); } } @@ -338,7 +338,7 @@ sub getJsonStatus { } } - $kernel->call(IKC=>post=>$rsvp, to_json(\%output)); + $kernel->call(IKC=>post=>$rsvp, encode_json(\%output)); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm index 687ceade0..ec7021151 100644 --- a/lib/WebGUI/Asset/File/GalleryFile/Photo.pm +++ b/lib/WebGUI/Asset/File/GalleryFile/Photo.pm @@ -19,7 +19,7 @@ use base 'WebGUI::Asset::File::GalleryFile'; use Carp qw( carp croak ); use Image::ExifTool qw( :Public ); -use JSON qw/ to_json from_json /; +use JSON qw/ encode_json decode_json /; use URI::Escape; use Tie::IxHash; @@ -176,7 +176,7 @@ sub getExifData { my $self = shift; return unless $self->get('exifData'); - return from_json( $self->get('exifData') ); + return decode_json( $self->get('exifData') ); } #---------------------------------------------------------------------------- @@ -397,7 +397,7 @@ sub updateExifDataFromFile { } $self->update({ - exifData => to_json( $info ), + exifData => encode_json( $info ), }); } diff --git a/lib/WebGUI/Asset/Wobject/Calendar.pm b/lib/WebGUI/Asset/Wobject/Calendar.pm index cfa999cff..ce522f132 100644 --- a/lib/WebGUI/Asset/Wobject/Calendar.pm +++ b/lib/WebGUI/Asset/Wobject/Calendar.pm @@ -24,7 +24,7 @@ use WebGUI::DateTime; use base 'WebGUI::Asset::Wobject'; use DateTime; -use JSON qw/to_json/; +use JSON qw/encode_json/; =head1 NAME @@ -627,7 +627,7 @@ ENDHTML my $feeds = $self->getFeeds(); $tab->raw(''); diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index fa73eab01..b5fbf9747 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -18,7 +18,7 @@ use strict; use base 'WebGUI::Asset::Wobject'; use Tie::IxHash; use WebGUI::HTMLForm; -use JSON qw/ to_json /; +use JSON qw/ encode_json /; use Digest::MD5; use WebGUI::Workflow::Instance; use WebGUI::Cache; @@ -952,7 +952,7 @@ sub getBadgeSelector { }; } $js = ''; %options = (%options,%{$badges}); $output .= WebGUI::Form::selectBox($self->session,{ diff --git a/lib/WebGUI/AssetPackage.pm b/lib/WebGUI/AssetPackage.pm index ec9447603..877f2b8d1 100644 --- a/lib/WebGUI/AssetPackage.pm +++ b/lib/WebGUI/AssetPackage.pm @@ -65,7 +65,7 @@ sub exportPackage { my $storage = WebGUI::Storage->createTemp($self->session); foreach my $asset (@{$self->getLineage(["self","descendants"],{returnObjects=>1})}) { my $data = $asset->exportAssetData; - $storage->addFileFromScalar($data->{properties}{lineage}.".json", JSON->new->pretty->encode($data)); + $storage->addFileFromScalar($data->{properties}{lineage}.".json", JSON->new->utf8->pretty->encode($data)); foreach my $storageId (@{$data->{storage}}) { my $assetStorage = WebGUI::Storage->get($self->session, $storageId); $assetStorage->tar($storageId.".storage", $storage); @@ -213,7 +213,7 @@ sub importPackage { next unless ($decompressed->getFileExtension($file) eq "json"); $error->info("Found data file $file"); my $data = eval{ - JSON->new->relaxed(1)->decode($decompressed->getFileContentsAsScalar($file)) + JSON->new->utf8->relaxed(1)->decode($decompressed->getFileContentsAsScalar($file)) }; if ($@ || $data->{properties}{assetId} eq "" || $data->{properties}{className} eq "" || $data->{properties}{revisionDate} eq "") { $error->error("package corruption: ".$@) if ($@); diff --git a/lib/WebGUI/Commerce/Transaction.pm b/lib/WebGUI/Commerce/Transaction.pm index f2934245c..3a7ffad9f 100644 --- a/lib/WebGUI/Commerce/Transaction.pm +++ b/lib/WebGUI/Commerce/Transaction.pm @@ -18,7 +18,7 @@ package WebGUI::Commerce::Transaction; use strict; use WebGUI::SQL; use WebGUI::Commerce::Payment; -use JSON qw/ from_json to_json /; +use JSON qw/ decode_json encode_json /; #------------------------------------------------------------------- @@ -615,12 +615,12 @@ sub shippingOptions { $shippingOptions = shift; if (scalar (keys %{$shippingOptions})) { - $self->{_properties}{shippingOptions} = to_json($shippingOptions); + $self->{_properties}{shippingOptions} = encode_json($shippingOptions); $self->session->db->write("update transaction set shippingOptions=? where transactionId=?",[$self->{_properties}{shippingOptions},$self->{_transactionId}]); } return {} unless defined $self->{_properties}{shippingOptions}; - return from_json($self->{_properties}{shippingOptions}); + return decode_json($self->{_properties}{shippingOptions}); } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Operation/Spectre.pm b/lib/WebGUI/Operation/Spectre.pm index 01c6d0288..9c506c0e4 100644 --- a/lib/WebGUI/Operation/Spectre.pm +++ b/lib/WebGUI/Operation/Spectre.pm @@ -122,7 +122,7 @@ sub www_spectreGetSiteData { } $siteData{cron} = \@schedules; } - return JSON::to_json(\%siteData); + return JSON::encode_json(\%siteData); } #------------------------------------------------------------------- @@ -169,8 +169,8 @@ sub www_spectreStatus { } my %data = ( - workflow => from_json($workflowResult), - cron => from_json($cronResult), + workflow => decode_json($workflowResult), + cron => decode_json($cronResult), ); my $workflowCount = @{ $data{workflow}{Suspended} } + @{ $data{workflow}{Waiting} } + @{ $data{workflow}{Running} }; diff --git a/lib/WebGUI/Operation/Workflow.pm b/lib/WebGUI/Operation/Workflow.pm index 665528a50..8804714b3 100644 --- a/lib/WebGUI/Operation/Workflow.pm +++ b/lib/WebGUI/Operation/Workflow.pm @@ -21,7 +21,7 @@ use WebGUI::Workflow::Activity; use WebGUI::Workflow::Instance; use WebGUI::Utility; use POE::Component::IKC::ClientLite; -use JSON qw/ from_json /; +use JSON qw/ decode_json /; =head1 NAME @@ -337,7 +337,7 @@ sub www_editWorkflowPriority { return $ac->render($output, $i18n->get('show running workflows')); } - my $responseHref = from_json($resultJson); + my $responseHref = decode_json($resultJson); my $message = $i18n->get($responseHref->{message}) || $i18n->get('edit priority unknown error'); return $ac->render($message, $i18n->get('show running workflows')); @@ -577,7 +577,7 @@ ENDCODE } if (defined $workflowResult) { - my $workflowsHref = from_json($workflowResult); + my $workflowsHref = decode_json($workflowResult); my $workflowTitleFor = $session->db->buildHashRef(<<""); SELECT wi.instanceId, w.title diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index c504e8325..5aa0bc8cc 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -398,7 +398,7 @@ sub showDebug { $form->{$key} = "********"; } } - $text = JSON->new->pretty->encode($form); + $text = JSON->new->utf8->pretty->encode($form); $text =~ s/&/&/sg; $text =~ s/>/>/sg; $text =~ s/getScratch('events')) { - $eventList = from_json($instance->getScratch('events')); - $feedList = from_json($instance->getScratch('feeds')); + $eventList = decode_json($instance->getScratch('events')); + $feedList = decode_json($instance->getScratch('feeds')); } else { my $ua = LWP::UserAgent->new(agent => "WebGUI"); @@ -356,8 +356,8 @@ sub execute { } while (@$eventList) { if ($startTime + 55 < time()) { - $instance->setScratch('events', to_json($eventList)); - $instance->setScratch('feeds', to_json($feedList)); + $instance->setScratch('events', encode_json($eventList)); + $instance->setScratch('feeds', encode_json($feedList)); return $self->WAITING; } my $eventData = shift @$eventList; diff --git a/lib/WebGUI/Workflow/Activity/GetSyndicatedContent.pm b/lib/WebGUI/Workflow/Activity/GetSyndicatedContent.pm index 7f338f3de..9519b4188 100644 --- a/lib/WebGUI/Workflow/Activity/GetSyndicatedContent.pm +++ b/lib/WebGUI/Workflow/Activity/GetSyndicatedContent.pm @@ -96,7 +96,7 @@ sub execute { # if there are urls left, we need to process again if (scalar(@syndicatedUrls) > 0) { - $instance->setScratch("syndicatedUrls", JSON::to_json(\@syndicatedUrls)); + $instance->setScratch("syndicatedUrls", JSON::encode_json(\@syndicatedUrls)); return $self->WAITING; } $instance->deleteScratch("syndicatedUrls"); @@ -120,7 +120,7 @@ sub getSyndicatedUrls { my $instance = shift; my $syndicatedUrls = $instance->getScratch("syndicatedUrls"); if ($syndicatedUrls) { - return JSON::from_json($syndicatedUrls); + return JSON::decode_json($syndicatedUrls); } my $urls = []; @@ -131,7 +131,7 @@ sub getSyndicatedUrls { foreach my $asset (@$assets) { push @$urls, split(/\s+/, $asset->getRssUrl); } - $instance->setScratch("syndicatedUrls", JSON::to_json($urls)); + $instance->setScratch("syndicatedUrls", JSON::encode_json($urls)); return $urls; } diff --git a/lib/WebGUI/Workflow/Cron.pm b/lib/WebGUI/Workflow/Cron.pm index cb43f8d8b..df71cb891 100644 --- a/lib/WebGUI/Workflow/Cron.pm +++ b/lib/WebGUI/Workflow/Cron.pm @@ -117,7 +117,7 @@ sub get { my $name = shift; if ($name eq "parameters") { if (exists $self->{_data}{parameters} && $self->{_data}{parameters} ne "") { - my $parameters = JSON::from_json($self->{_data}{$name}); + my $parameters = JSON::decode_json($self->{_data}{$name}); return $parameters->{parameters}; } else { @@ -303,7 +303,7 @@ sub set { $self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className}; $self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName}; if (exists $properties->{parameters}) { - $self->{_data}{parameters} = JSON->new->pretty->encode({parameters => $properties->{parameters}}); + $self->{_data}{parameters} = JSON->new->utf8->pretty->encode({parameters => $properties->{parameters}}); } $self->{_data}{enabled} = 0 unless ($self->{_data}{workflowId}); my $spectre = WebGUI::Workflow::Spectre->new($self->session); diff --git a/lib/WebGUI/Workflow/Instance.pm b/lib/WebGUI/Workflow/Instance.pm index e703420d2..9045df2ed 100644 --- a/lib/WebGUI/Workflow/Instance.pm +++ b/lib/WebGUI/Workflow/Instance.pm @@ -66,7 +66,7 @@ sub create { my ($isSingleton) = $session->db->quickArray("select count(*) from Workflow where workflowId=? and mode='singleton'",[$properties->{workflowId}]); my $params = (exists $properties->{parameters}) - ? JSON->new->pretty->encode({parameters => $properties->{parameters}}) + ? JSON->new->utf8->pretty->encode({parameters => $properties->{parameters}}) : undef; my ($count) = $session->db->quickArray("select count(*) from WorkflowInstance where workflowId=? and parameters=?",[$properties->{workflowId},$params]); return undef if ($isSingleton && $count); @@ -148,7 +148,7 @@ sub get { my $name = shift; if ($name eq "parameters") { if (exists $self->{_data}{parameters}) { - my $parameters = JSON::from_json($self->{_data}{$name}); + my $parameters = JSON::decode_json($self->{_data}{$name}); return $parameters->{parameters}; } else { @@ -421,7 +421,7 @@ sub set { $self->{_data}{className} = (exists $properties->{className}) ? $properties->{className} : $self->{_data}{className}; $self->{_data}{methodName} = (exists $properties->{methodName}) ? $properties->{methodName} : $self->{_data}{methodName}; if (exists $properties->{parameters}) { - $self->{_data}{parameters} = JSON->new->pretty->encode({parameters => $properties->{parameters}}); + $self->{_data}{parameters} = JSON->new->utf8->pretty->encode({parameters => $properties->{parameters}}); } $self->{_data}{currentActivityId} = (exists $properties->{currentActivityId}) ? $properties->{currentActivityId} : $self->{_data}{currentActivityId}; $self->{_data}{lastUpdate} = time();