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