Skip to content

Support paths with + in List API #6700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you avoid the pragma with an approach like #6693?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am getting an unused variable warning, and I don't see how the code you linked to doesn't generate the same warning. Is there any trick I need to employ?

#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