Skip to content

Commit 55ab885

Browse files
Support paths with + in List API (#6700)
1 parent 4507ad1 commit 55ab885

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

FirebaseStorage/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Unreleased
2+
- [fixed] Fixed an issue with the List API that prevented listing of locations
3+
that contain the "+" sign.
4+
15
# 7.0.0
26
- [changed] The global variable `FIRStorageVersionString` is deleted.
37
`FirebaseVersion()` or `FIRFirebaseVersion()` should be used instead.

FirebaseStorage/Sources/FIRStorageUtils.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ + (NSURLRequest *)defaultRequestForPath:(FIRStoragePath *)path
101101
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:queryParams[key]]];
102102
}
103103
[components setQueryItems:queryItems];
104+
// NSURLComponents does not encode "+" as "%2B". This is however required by our backend, as
105+
// it treats "+" as a shorthand encoding for spaces. See also
106+
// https://stackoverflow.com/questions/31577188/how-to-encode-into-2b-with-nsurlcomponents
107+
[components setPercentEncodedQuery:[[components percentEncodedQuery]
108+
stringByReplacingOccurrencesOfString:@"+"
109+
withString:@"%2B"]];
104110

105111
NSString *encodedPath = [self encodedURLForPath:path];
106112
[components setPercentEncodedPath:encodedPath];

FirebaseStorage/Tests/Unit/FIRStorageListTests.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,42 @@ - (void)testListWithPageSizeAndPageToken {
152152
[FIRStorageTestHelpers waitForExpectation:self];
153153
}
154154

155+
- (void)testPercentEncodesPlusToken {
156+
XCTestExpectation *expectation = [self expectationWithDescription:@"testPercentEncodesPlusToken"];
157+
NSURL *expectedURL = [NSURL URLWithString:@"https://firebasestorage.googleapis.com/v0/b/bucket/"
158+
@"o?prefix=%2Bfoo/&delimiter=/"];
159+
160+
self.fetcherService.testBlock =
161+
^(GTMSessionFetcher *fetcher, GTMSessionFetcherTestResponse response) {
162+
#pragma clang diagnostic push
163+
#pragma clang diagnostic ignored "-Warc-retain-cycles"
164+
XCTAssertEqualObjects(fetcher.request.URL, expectedURL); // Implicitly retains self
165+
XCTAssertEqualObjects(fetcher.request.HTTPMethod, @"GET");
166+
#pragma clang diagnostic pop
167+
NSHTTPURLResponse *httpResponse = [[NSHTTPURLResponse alloc] initWithURL:fetcher.request.URL
168+
statusCode:200
169+
HTTPVersion:kHTTPVersion
170+
headerFields:nil];
171+
response(httpResponse, nil, nil);
172+
};
173+
174+
FIRStoragePath *path =
175+
[FIRStoragePath pathFromString:@"https://firebasestorage.googleapis.com/v0/b/bucket/0/+foo"];
176+
FIRStorageReference *ref = [[FIRStorageReference alloc] initWithStorage:self.storage path:path];
177+
FIRStorageListTask *task = [[FIRStorageListTask alloc]
178+
initWithReference:ref
179+
fetcherService:self.fetcherService
180+
dispatchQueue:self.dispatchQueue
181+
pageSize:nil
182+
previousPageToken:nil
183+
completion:^(FIRStorageListResult *result, NSError *error) {
184+
[expectation fulfill];
185+
}];
186+
[task enqueue];
187+
188+
[FIRStorageTestHelpers waitForExpectation:self];
189+
}
190+
155191
- (void)testListWithResponse {
156192
XCTestExpectation *expectation = [self expectationWithDescription:@"testListWithErrorResponse"];
157193

0 commit comments

Comments
 (0)