Skip Menu |

This queue is for tickets about the JSON CPAN distribution.

Report information
The Basics
Id: 19646
Status: resolved
Priority: 0/
Queue: JSON

People
Owner: Nobody in particular
Requestors: philip.tellis [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.05
Fixed in: (no value)



Subject: Make utf8 encode work with perl < 5.8
JSON::Parser behaves badly with utf8 data in perl version below 5.8 as use utf8 isn't implemented. This patch uses Unicode::String (available from CPAN at http://search.cpan.org/~gaas/Unicode-String-2.09/String.pm) to do utf8 decoding in older versions of perl.
Subject: json-utf8.diff
--- lib/perl5/site_perl/5.6.1/JSON/Parser.pm Thu May 4 03:16:27 2006 +++ lib/perl5/site_perl/5.6.1/JSON/Parser.pm Fri Jun 2 00:45:30 2006 @@ -8,6 +8,9 @@ use vars qw($VERSION $USE_UTF8); use strict; use JSON (); +BEGIN { + eval {use Unicode::String;} if $] < 5.008 ; +} $VERSION = '1.02'; @@ -99,7 +102,14 @@ $u .= $ch; } my $f = chr(hex($u)); - utf8::encode( $f ) if($USE_UTF8); + if($USE_UTF8){ + utf8::encode( $f ) if($USE_UTF8); + } + elsif(length($f) == 1 && ord($f) <= 0xff){ + my $us = new Unicode::String; + $us->latin1($f); + $f = $us->utf8; + } $s .= $f; } else{