Skip to content

Commit

Permalink
Support paths with + in List API
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Oct 8, 2020
1 parent 672256e commit e60654e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions FirebaseStorage/Sources/FIRStorageUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ + (NSURLRequest *)defaultRequestForPath:(FIRStoragePath *)path
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:queryParams[key]]];
}
[components setQueryItems:queryItems];
// NSURLComponents does not encode "+" as "%2B". This is however required by our backend, as
// it treats "+" as a shorthand encoding for spaces. See also
// https://stackoverflow.com/questions/31577188/how-to-encode-into-2b-with-nsurlcomponents
[components setPercentEncodedQuery:[[components percentEncodedQuery]
stringByReplacingOccurrencesOfString:@"+"
withString:@"%2B"]];

NSString *encodedPath = [self encodedURLForPath:path];
[components setPercentEncodedPath:encodedPath];
Expand Down
36 changes: 36 additions & 0 deletions FirebaseStorage/Tests/Unit/FIRStorageListTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,42 @@ - (void)testListWithPageSizeAndPageToken {
[FIRStorageTestHelpers waitForExpectation:self];
}

- (void)testPercentEncodesPlusToken {
XCTestExpectation *expectation = [self expectationWithDescription:@"testPercentEncodesPlusToken"];
NSURL *expectedURL = [NSURL URLWithString:@"https://firebasestorage.googleapis.com/v0/b/bucket/"
@"o?prefix=%2Bfoo/&delimiter=/"];

self.fetcherService.testBlock =
^(GTMSessionFetcher *fetcher, GTMSessionFetcherTestResponse response) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
XCTAssertEqualObjects(fetcher.request.URL, expectedURL); // Implicitly retains self
XCTAssertEqualObjects(fetcher.request.HTTPMethod, @"GET");
#pragma clang diagnostic pop
NSHTTPURLResponse *httpResponse = [[NSHTTPURLResponse alloc] initWithURL:fetcher.request.URL
statusCode:200
HTTPVersion:kHTTPVersion
headerFields:nil];
response(httpResponse, nil, nil);
};

FIRStoragePath *path =
[FIRStoragePath pathFromString:@"https://firebasestorage.googleapis.com/v0/b/bucket/0/+foo"];
FIRStorageReference *ref = [[FIRStorageReference alloc] initWithStorage:self.storage path:path];
FIRStorageListTask *task = [[FIRStorageListTask alloc]
initWithReference:ref
fetcherService:self.fetcherService
dispatchQueue:self.dispatchQueue
pageSize:nil
previousPageToken:nil
completion:^(FIRStorageListResult *result, NSError *error) {
[expectation fulfill];
}];
[task enqueue];

[FIRStorageTestHelpers waitForExpectation:self];
}

- (void)testListWithResponse {
XCTestExpectation *expectation = [self expectationWithDescription:@"testListWithErrorResponse"];

Expand Down

0 comments on commit e60654e

Please sign in to comment.