You are here: Foswiki>Tasks Web>Item13397 (05 Jul 2015, GeorgeClark)Edit Attach

Item13397: Foswiki::Serialise::Json uses JSON::Any, which generates UNICODE

pencil
Priority: Urgent
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: Unicode
Branches:
Reported By: CrawfordCurrie
Waiting For:
Last Change By: GeorgeClark
JSON::Any is deprecated in favour of JSON (see perldoc JSON::Any) and generates unicode anyway.

Foswiki::Serialise::Json (and any other usages of JSON::Any) need to be recoded to use JSON.

diff --git a/core/lib/Foswiki/Serialise/Json.pm b/core/lib/Foswiki/Serialise/Jso
index 39ca23e..c51b8a8 100644
--- a/core/lib/Foswiki/Serialise/Json.pm
+++ b/core/lib/Foswiki/Serialise/Json.pm
@@ -12,7 +12,7 @@ package Foswiki::Serialise::Json;
 
 use strict;
 use warnings;
-use JSON::Any;
+use JSON;
 
 =begin TML
 
@@ -26,17 +26,13 @@ sub new {
     return $this;
 }
 
-#The JSON serialisation uses JSON::Any to select the 'best' available JSON impl
-
-#TODO: should really use encode_json / decode_json as those will use utf8,
-#but er, that'll cause other issues - as QUERY will blast the json into a topic
 sub write {
     my $module = shift;
     my ($result) = @_;
 
     return '' if ( not( defined($result) ) );
-    my $j = JSON::Any->new( allow_nonref => 1 );
-    return $j->to_json( $result, { allow_nonref => 1 } );
+    my $j = JSON->new->allow_nonref( 1 );
+    return $j->encode( $result );
 }
 
 #TODO: should really use encode_json / decode_json as those will use utf8,

Testcase (by George):

git cherry-pick 980aebc2a4c9ca55640ed0ed849ad94ef5d5f0ae

in TestCases/TestCaseUtf8Errors

Note that my patch above is from the utf8 branch and is incomplete; there are two calls in that module, and they will return utf8 binary strings. The trunk will need to decode the utf8 to unicode and re-encode the result in the {Site}{CharSet} e.g.

return Encode::encode($Foswiki::cfg{Site}{Charset}, Encode::decode('utf-8', $result));

-- CrawfordCurrie - 07 May 2015

Fixed in utf8 branch, awaiting merge

-- Main.CrawfordCurrie - 17 May 2015 - 10:13
 

ItemTemplate edit

Summary Foswiki::Serialise::Json uses JSON::Any, which generates UNICODE
ReportedBy CrawfordCurrie
Codebase 1.2.0 beta1, trunk
SVN Range
AppliesTo Engine
Component Unicode
Priority Urgent
CurrentState Closed
WaitingFor
Checkins
TargetRelease major
ReleasedIn 2.0.0
CheckinsOnBranches
trunkCheckins
masterCheckins
ItemBranchCheckins
Release01x01Checkins
Topic revision: r5 - 05 Jul 2015, GeorgeClark - This page was cached on 27 Jun 2016 - 04:17.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License