Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-GitHub CPAN distribution.

Report information
The Basics
Id: 97737
Status: resolved
Priority: 0/
Queue: Net-GitHub

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.66
Fixed in: (no value)



Subject: Sending UTF-8 encoded data causes a JSON parse error
When trying to create a repository with a UTF-8 encoded description, I get a "Problems parsing JSON" error.  Here is an example.

use utf8;    # Remove this and it works

use Net::Github::V3;

my $gh = Net::GitHub::V3->new(
    access_token => "FILL THIS IN",
);

Show quoted text
# Problems parsing JSON at /Users/schwern/perl5/perlbrew/perls/perl-5.18.1-thread/lib/site_perl/5.18.1/Net/GitHub/V3/Repos.pm line 67.
$gh->repos->create({
    name        => "Foo-Bar-Baz",
    description => "Testing ünicode descriptions",
});

The problem appears to be the charset which LWP is posting as is not UTF-8.  If you make that explicit with $req->content_type("text/plain; charset='utf8'"); and $req->content(encode_utf8($json)); it works... but then non-UTF8 encoded strings come through garbled... at least it doesn't error.

I don't know how encodings work well enough to properly solve this.  Here's an article I used as a guide.
http://blogs.perl.org/users/domm/2010/11/posting-utf8-data-using-lwpuseragent.html
actually if I try something like below it also works use utf8; use Encode; my $x = $gh->repos->create({ name => "Foo-Bar-Baz", description => encode_utf8("Testing ünicode descriptions"), }); does it make sense? Thanks
Subject: Re: [rt.cpan.org #97737] Sending UTF-8 encoded data causes a JSON parse error
Date: Tue, 05 Aug 2014 14:13:10 -0700
To: bug-Net-GitHub [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
Thank you, that works! I don't entirely understand what it is doing or why it is necessary. I probably misunderstand what "use utf8" does. I had assumed it changed the internal representation of Perl strings to UTF-8, but I guess I'm wrong? Either way, would a doc section on handling UTF-8 be worthwhile?
I added the code in the examples. it will be shipped on next version. Thanks On Tue Aug 05 17:13:29 2014, schwern@pobox.com wrote: Show quoted text
> Thank you, that works! > > I don't entirely understand what it is doing or why it is necessary. I > probably misunderstand what "use utf8" does. I had assumed it changed > the internal representation of Perl strings to UTF-8, but I guess I'm wrong? > > Either way, would a doc section on handling UTF-8 be worthwhile?