Skip to content
This repository was archived by the owner on Jan 24, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NSURL+QueryDictionary/NSURL+QueryDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ - (NSURL*) uq_URLByAppendingQueryDictionary:(NSDictionary*) queryDictionary {
- (NSURL *)uq_URLByAppendingQueryDictionary:(NSDictionary *)queryDictionary
withSortedKeys:(BOOL)sortedKeys
{
NSMutableArray *queries = self.query ? @[self.query].mutableCopy : @[].mutableCopy;
NSMutableArray *queries = [self.query length] > 0 ? @[self.query].mutableCopy : @[].mutableCopy;
NSString *dictionaryQuery = [queryDictionary uq_URLQueryStringWithSortedKeys:sortedKeys];
if (dictionaryQuery) {
[queries addObject:dictionaryQuery];
Expand Down
8 changes: 8 additions & 0 deletions UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ - (void) testShouldAppendASimpleQuery {
@"Did not create correctly formatted URL");
}

- (void) testShouldAppendWhenURLContainsJustQueryBegin {
NSDictionary *dict = @{@"key":@"value"};
XCTAssertEqualObjects([URL(@"http://www.foo.com/path?")
uq_URLByAppendingQueryDictionary:dict].absoluteString,
@"http://www.foo.com/path?key=value",
@"Did not create correctly formatted URL");
}

- (void) testShouldAppendToExistingQueryWithFragment {
NSDictionary *dict = @{@"cat":@"cheese", @"foo":@"bar"};
XCTAssertEqualObjects([URL(@"http://www.foo.com?aKey=aValue&another=val2#fragment")
Expand Down