Subject: | upload() multi-byte status fails with Net::OAuth 0.26 |
since its version 0.26, Net::OAuth requires non-ASCII parameters well
decoded to make signature.
Net::Twitter now passes that kind of parameters in UTF-8 octets form to
Net::OAuth. ( as a result, Net::OAuth makes invalid signature for
non-ASCII parameters )
I attach a patch file to solve this problem.
it is for lib/Net/Twiiter/Role/OAuth.pm and t/unicode.t .
please check it.
thx.
Subject: | Net-Twitter_3.13003_for_Net-OAuth_0.26.diff |
=== modified file 'lib/Net/Twitter/Role/OAuth.pm'
--- lib/Net/Twitter/Role/OAuth.pm 2010-06-17 14:49:16 +0000
+++ lib/Net/Twitter/Role/OAuth.pm 2010-06-17 16:23:28 +0000
@@ -5,6 +5,7 @@
use URI;
use Digest::SHA;
use List::Util qw/first/;
+use Encode qw/decode_utf8/;
requires qw/_add_authorization_header ua/;
@@ -167,7 +168,12 @@
my $uri = $msg->uri->clone;
$uri->query($msg->content) if $msg->content_type eq 'application/x-www-form-urlencoded';
- my $args = { $uri->query_form };
+ ## Net::OAuth 0.26 and above requires decoded string.
+ ## See perldoc Net::OAuth section I18N
+ my $args =
+ $Net::OAuth::VERSION ge '0.26' ?
+ { map { utf8::is_utf8($_) ? $_ : decode_utf8($_) } $uri->query_form } :
+ { $uri->query_form };
local $Net::OAuth::SKIP_UTF8_DOUBLE_ENCODE_CHECK = 1;
=== modified file 't/unicode.t'
--- t/unicode.t 2010-06-17 14:49:16 +0000
+++ t/unicode.t 2010-06-17 16:24:51 +0000
@@ -9,7 +9,7 @@
eval "use LWP::UserAgent 5.819";
plan skip_all => 'LWP::UserAgent >= 5.819 required' if $@;
-plan tests => 9;
+plan tests => 11;
my $req;
my $ua = LWP::UserAgent->new;
@@ -36,6 +36,16 @@
$nt->access_token('token');
$nt->access_token_secret('secret');
+my $meta = $nt->meta;
+$meta->make_mutable;
+$meta->add_around_method_modifier('_make_oauth_request', sub {
+ my ($orig, $self, $type, %args) = @_;
+
+ ok utf8::is_utf8($args{extra_params}{status}), "status must be decoded";
+ $self->$orig($type, %args);
+ });
+$meta->make_immutable;
+
# "Hello world!" in traditional Chinese if Google translate is correct
my $status = "\x{4E16}\x{754C}\x{60A8}\x{597D}\x{FF01}";