Skip to content

Commit 4974830

Browse files
authored
Merge pull request #45 from WinnieLYT/winnie-lyt/tdoauth
Fix dropping collection values in GET calls
2 parents 7648118 + 68507ad commit 4974830

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

Example/Tests/Compat.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,10 @@ -(void)testGetRequestWithInvalidAdditionalParameters
177177
{
178178
NSURLRequest *getRequest = [self.class makeGetRequestWithInvalidAdditionalParameters];
179179
NSString *url = [[getRequest URL] absoluteString];
180-
XCTAssert([url isEqualToString:@"http://api.example.com/service?foo=bar"],
181-
"url does not match expected value");
180+
XCTAssert([url containsString: @"http://api.example.com/service?"], @"url does not match expected value");
181+
XCTAssert([url containsString: @"foo=bar"], @"url does not match expected value");
182+
XCTAssert([url containsString: @"fizz=%28%0A%20%20%20%201%2C%0A%20%20%20%202%0A%29"], @"url does not match expected value");
183+
XCTAssert([url containsString: @"buzz=%7B%0A%20%20%20%20bar%20%3D%20foo%3B%0A%7D"], @"url does not match expected value");
182184

183185
NSString *contentType = [getRequest valueForHTTPHeaderField: @"Content-Type"];
184186
XCTAssertNil(contentType,

Example/Tests/TestTDOQueryItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestTDOQueryItem: XCTestCase {
2323
}
2424

2525
func testStringParam() {
26-
guard let queryItems = TDOQueryItem.getItems(from: Self.paramDictionary, isCollectionValuesSupported: true) else {
26+
guard let queryItems = TDOQueryItem.getItems(from: Self.paramDictionary) else {
2727
assertionFailure("TDOQueryItem: parse parameters failed.")
2828
return
2929
}

Source/compat/TDOAuth.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,7 @@ internal class TDOQueryItem : NSObject {
6262
self.stringValue = Self.getStringValue(by: rawValue)
6363
}
6464

65-
private class func getStringValue(by rawValue: Any, isCollectionValuesSupported: Bool = true) -> String? {
66-
if !isCollectionValuesSupported,
67-
(rawValue is Array<Any> || rawValue is Dictionary<AnyHashable, Any>) {
68-
return nil
69-
}
65+
private class func getStringValue(by rawValue: Any) -> String? {
7066
var formattedValue: String?
7167
switch rawValue {
7268
case let losslessString as CustomStringConvertible:
@@ -86,17 +82,15 @@ internal class TDOQueryItem : NSObject {
8682
return formattedValue
8783
}
8884

89-
class func getItems(from dictionary: [AnyHashable: Any]?, isCollectionValuesSupported: Bool = true) -> [TDOQueryItem]? {
85+
class func getItems(from dictionary: [AnyHashable: Any]?) -> [TDOQueryItem]? {
9086
guard let dic = dictionary else { return nil }
9187
var queryItems = [TDOQueryItem]()
9288

9389
for (key, value) in dic {
9490
guard let key = key as? String else { continue }
95-
if Self.getStringValue(by: value, isCollectionValuesSupported: isCollectionValuesSupported) == nil {
96-
if isCollectionValuesSupported {
97-
/// `value` is not a valid type - skipping
98-
assertionFailure("TDOAuth: failed to casting the parameter: \(value) for the key: \(key)")
99-
}
91+
if Self.getStringValue(by: value) == nil {
92+
/// `value` is not a valid type - skipping
93+
assertionFailure("TDOAuth: failed to casting the parameter: \(value) for the key: \(key)")
10094
continue
10195
}
10296
let queryItem = TDOQueryItem(name: key, rawValue: value)
@@ -279,7 +273,7 @@ internal class TDOQueryItem : NSObject {
279273
signatureMethod: TDOAuthSignatureMethod) -> URLRequest! {
280274

281275
return self.urlRequest(forPath: unencodedPathWithoutQuery,
282-
queryItems: TDOQueryItem.getItems(from: unencodedParameters, isCollectionValuesSupported: method == "POST") ?? [],
276+
queryItems: TDOQueryItem.getItems(from: unencodedParameters) ?? [],
283277
host: host,
284278
consumerKey: consumerKey,
285279
consumerSecret: consumerSecret,

TDOAuth.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'TDOAuth'
11-
s.version = '1.6.2'
11+
s.version = '1.6.3'
1212
s.summary = 'Elegant, simple and compliant OAuth 1.x solution.'
1313

1414
s.description = <<-DESC

0 commit comments

Comments
 (0)