Skip to content

Commit

Permalink
fixed normalized_parameter for invlid key order
Browse files Browse the repository at this point in the history
  • Loading branch information
hidek committed Feb 8, 2010
1 parent 9f7ec46 commit 2a1b1ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/OAuth/Lite/Util.pm
Expand Up @@ -162,19 +162,19 @@ according to the way OAuth Core spec defines.
sub normalize_params {
my $params = shift;
my @pairs = ();
for my $k (keys %$params) {
for my $k (sort keys %$params) {
if (!ref $params->{$k}) {
push @pairs,
sprintf(q{%s=%s}, encode_param($k), encode_param($params->{$k}));
}
elsif (ref $params->{$k} eq 'ARRAY') {
for my $v (@{ $params->{$k} }) {
for my $v (sort @{ $params->{$k} }) {
push @pairs,
sprintf(q{%s=%s}, encode_param($k), encode_param($v));
}
}
}
return join('&', sort { $a cmp $b } @pairs);
return join('&', @pairs);
}

=head2 parse_auth_header($header)
Expand Down
3 changes: 2 additions & 1 deletion t/01_util.t
Expand Up @@ -87,8 +87,9 @@ is(OAuth::Lite::Util::normalize_params({ b => 1, a => 2 }), 'a=2&b=1');
# From http://oauth.net/core/1.0#anchor14
my %hash = (
a => 1,
a1 => 1,
c => 'hi there',
f => [25, 50, 'a'],
z => ['p', 't'],
);
is(OAuth::Lite::Util::normalize_params(\%hash), 'a=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t');
is(OAuth::Lite::Util::normalize_params(\%hash), 'a=1&a1=1&c=hi%20there&f=25&f=50&f=a&z=p&z=t');

0 comments on commit 2a1b1ce

Please sign in to comment.