Skip to content

Commit 02132ce

Browse files
Adrxxmikehardy
andauthored
fix(storage): bug when getting the root ref of a bucket (#3455)
A bug crashes the app when trying to list objects, root urls don't have a "/" so rangeOfString gives location == NSNotFound, if it goes unchecked rangeOfSlash.location + 5 creates range outside the bounds Co-authored-by: Mike Hardy <[email protected]>
1 parent 743edf8 commit 02132ce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/storage/ios/RNFBStorage/RNFBStorageModule.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,11 @@ - (void)addUploadTaskObservers:(FIRStorageUploadTask *)uploadTask appDisplayName
517517

518518
- (FIRStorageReference *)getReferenceFromUrl:(NSString *)url app:(FIRApp *)firebaseApp {
519519
NSString *pathWithBucketName = [url substringWithRange:NSMakeRange(5, [url length] - 5)];
520-
NSString *bucket = [url substringWithRange:NSMakeRange(0, [pathWithBucketName rangeOfString:@"/"].location + 5)];
520+
NSString *bucket = url;
521+
NSRange rangeOfSlash = [pathWithBucketName rangeOfString:@"/"];
522+
if (rangeOfSlash.location != NSNotFound) {
523+
bucket = [url substringWithRange:NSMakeRange(0, rangeOfSlash.location + 5)];
524+
}
521525
return [[FIRStorage storageForApp:firebaseApp URL:bucket] referenceForURL:url];
522526
}
523527

0 commit comments

Comments
 (0)