-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed URI encoding issue (Twitter API v1.1 is more stringent)
Bug reporteb by Nick Andrew (@elronxenu) 2013-02-27 via Twitter. We used to rely on HTTP::Requet::Common to encode arguments, but it relies on URI which doesn't encode the full set of values required by the OAuth spec. We now use Net::OAuth::Message to encode paramters.
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!perl | ||
use warnings; | ||
use strict; | ||
use URI; | ||
use Net::Twitter; | ||
use Net::OAuth::Message; | ||
use Test::More; | ||
|
||
plan tests => 2; | ||
|
||
# Ensure post args are encoded per the OAuth spec | ||
# | ||
# We assume Net::OAuth does the right thing, here. | ||
# | ||
# Bug reported by Nick Andrew (@elronxenu) 2013-02-27 | ||
|
||
my $nt = Net::Twitter->new( | ||
traits => [qw/API::RESTv1_1/], | ||
consumer_key => 'mykey', | ||
consumer_secret => 'mysecret', | ||
access_token => 'mytoken', | ||
access_token_secret => 'mytokensecret', | ||
); | ||
|
||
my $req; | ||
$nt->ua->add_handler(request_send => sub { | ||
$req = shift; | ||
my $res = HTTP::Response->new(200, 'OK'); | ||
$res->content('{}'); | ||
|
||
return $res; | ||
}); | ||
|
||
my $text = q[Bob's your !@##$%^&*(){}} uncle!]; | ||
$nt->new_direct_message({ screen_name => 'perl_api', text => $text }); | ||
|
||
my $encoded_text = Net::OAuth::Message::encode($text); | ||
like $req->content, qr/\E$encoded_text/, 'properly encoded'; | ||
|
||
my $uri = URI->new($req->uri); | ||
$uri->query($req->content); | ||
my %params = $uri->query_form; | ||
is $params{text}, $text, 'decoded text matches'; |