use UTF8 JSON encoding and decoding universally

fixed: Import/Export of packages with international text is broken
This commit is contained in:
Graham Knop 2008-04-01 14:42:20 +00:00
parent 35bfeac0ef
commit 9ed284beec
16 changed files with 42 additions and 40 deletions

View file

@ -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

View file

@ -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 : $@");
}

View file

@ -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));
}

View file

@ -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));
}
#-------------------------------------------------------------------

View file

@ -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 ),
});
}

View file

@ -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('<script type="text/javascript">'."\n");
for my $feedId (keys %$feeds) {
$tab->raw("FeedsManager.addFeed('feeds','".$feedId."',".to_json($feeds->{$feedId}).");\n");
$tab->raw("FeedsManager.addFeed('feeds','".$feedId."',".encode_json($feeds->{$feedId}).");\n");
}
$tab->raw('</script>');

View file

@ -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 = '<script type="text/javascript">
var badges = '.to_json(\%badgeJS).';
var badges = '.encode_json(\%badgeJS).';
</script>';
%options = (%options,%{$badges});
$output .= WebGUI::Form::selectBox($self->session,{

View file

@ -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 ($@);

View file

@ -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});
}
#-------------------------------------------------------------------

View file

@ -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} };

View file

@ -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

View file

@ -398,7 +398,7 @@ sub showDebug {
$form->{$key} = "********";
}
}
$text = JSON->new->pretty->encode($form);
$text = JSON->new->utf8->pretty->encode($form);
$text =~ s/&/&amp;/sg;
$text =~ s/>/&gt;/sg;
$text =~ s/</&lt;/sg;

View file

@ -25,7 +25,7 @@ use WebGUI::DateTime;
use DateTime::TimeZone;
use LWP::UserAgent;
use JSON qw(to_json from_json);
use JSON qw(encode_json decode_json);
=head1 NAME
@ -92,8 +92,8 @@ sub execute {
my $eventList = [];
my $feedList;
if ($instance->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;

View file

@ -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;
}

View file

@ -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);

View file

@ -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();