Skip to content

Commit

Permalink
fixed Token::from_encoded. now it accepts both CRLF and LF
Browse files Browse the repository at this point in the history
  • Loading branch information
lyokato committed Jan 26, 2011
1 parent 5c28c8e commit 3c1c1da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changes
@@ -1,5 +1,8 @@
Revision history for Perl extension OAuth::Lite.

1.29 Wed Jan 26 16:46:00 2010
- Now Token::from_encoded doesn't use chomp and trim both CRLF and LF

1.28 Sun Jan 16 14:23:00 2010
- fixed typo
Thanks to tokuhirom.
Expand Down
2 changes: 1 addition & 1 deletion lib/OAuth/Lite.pm
Expand Up @@ -3,7 +3,7 @@ package OAuth::Lite;
use strict;
use warnings;

our $VERSION = "1.28";
our $VERSION = "1.29";
our $OAUTH_DEFAULT_VERSION = "1.0";

1;
Expand Down
5 changes: 4 additions & 1 deletion lib/OAuth/Lite/Token.pm
Expand Up @@ -116,7 +116,10 @@ Generate token from encoded line (that service provider provides as response of

sub from_encoded {
my ($class, $encoded) = @_;
chomp $encoded;

$encoded =~ s/\r\n$//;
$encoded =~ s/\n$//;

my $token = $class->new;
for my $pair (split /&/, $encoded) {
my ($key, $val) = split /=/, $pair;
Expand Down
11 changes: 10 additions & 1 deletion t/02_token.t
@@ -1,4 +1,4 @@
use Test::More tests => 15;
use Test::More tests => 21;

use OAuth::Lite::Token;

Expand All @@ -24,6 +24,15 @@ is($t3->token, 'foo');
is($t3->secret, 'bar');
ok(!$t3->callback_confirmed);

$t3 = OAuth::Lite::Token->from_encoded($encoded."\n");
is($t3->token, 'foo');
is($t3->secret, 'bar');
ok(!$t3->callback_confirmed);

$t3 = OAuth::Lite::Token->from_encoded($encoded."\r\n");
is($t3->token, 'foo');
is($t3->secret, 'bar');
ok(!$t3->callback_confirmed);

my $t4 = OAuth::Lite::Token->from_encoded(q{oauth_token=foo&oauth_token_secret=bar&oauth_callback_confirmed=true});
ok($t4->callback_confirmed);
Expand Down

0 comments on commit 3c1c1da

Please sign in to comment.