Skip to content

Commit

Permalink
moved sorting comparison in OAMutableURLRequest to use a 3.x compatib…
Browse files Browse the repository at this point in the history
…le method
  • Loading branch information
Mike Cugini committed Aug 16, 2011
1 parent d003850 commit 2efd04c
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions OAMutableURLRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ - (void)_generateNonce {
nonce = (NSString *)string;
}

NSInteger normalize(id obj1, id obj2, void *context)
{
NSArray *nameAndValue1 = [obj1 componentsSeparatedByString:@"="];
NSArray *nameAndValue2 = [obj2 componentsSeparatedByString:@"="];

NSString *name1 = [nameAndValue1 objectAtIndex:0];
NSString *name2 = [nameAndValue2 objectAtIndex:0];

NSComparisonResult comparisonResult = [name1 compare:name2];
if (comparisonResult == NSOrderedSame) {
NSString *value1 = [nameAndValue1 objectAtIndex:1];
NSString *value2 = [nameAndValue2 objectAtIndex:1];

comparisonResult = [value1 compare:value2];
}

return comparisonResult;
}


- (NSString *)_signatureBaseString {
// OAuth Spec, Section 9.1.1 "Normalize Request Parameters"
// build a sorted array of both request parameters and OAuth header parameters
Expand Down Expand Up @@ -178,24 +198,8 @@ - (NSString *)_signatureBaseString {
}
}

// Oauth Spec, Section 3.4.1.3.2 "Parameters Normalization"
NSArray *sortedPairs = [parameterPairs sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSArray *nameAndValue1 = [obj1 componentsSeparatedByString:@"="];
NSArray *nameAndValue2 = [obj2 componentsSeparatedByString:@"="];

NSString *name1 = [nameAndValue1 objectAtIndex:0];
NSString *name2 = [nameAndValue2 objectAtIndex:0];

NSComparisonResult comparisonResult = [name1 compare:name2];
if (comparisonResult == NSOrderedSame) {
NSString *value1 = [nameAndValue1 objectAtIndex:1];
NSString *value2 = [nameAndValue2 objectAtIndex:1];

comparisonResult = [value1 compare:value2];
}

return comparisonResult;
}];
// Oauth Spec, Section 3.4.1.3.2 "Parameters Normalization
NSArray *sortedPairs = [parameterPairs sortedArrayUsingFunction:normalize context:NULL];

NSString *normalizedRequestParameters = [sortedPairs componentsJoinedByString:@"&"];
[parameterPairs release];
Expand Down

0 comments on commit 2efd04c

Please sign in to comment.