diff --git a/GoogleDataTransport/CHANGELOG.md b/GoogleDataTransport/CHANGELOG.md index 58b10f3a984..ea18591d32a 100644 --- a/GoogleDataTransport/CHANGELOG.md +++ b/GoogleDataTransport/CHANGELOG.md @@ -1,5 +1,6 @@ # Unreleased - Legacy pre Xcode 10 compatibility checks removed. (#6486) +- `GDTCORDirectorySizeTracker` crash fixed. (#6540) # v7.4.0 - Limit disk space consumed by GoogleDataTransport to store events. (#6365) diff --git a/GoogleDataTransport/GDTCORLibrary/GDTCORDirectorySizeTracker.m b/GoogleDataTransport/GDTCORLibrary/GDTCORDirectorySizeTracker.m index 59aa46d7bd5..4f678b70cea 100644 --- a/GoogleDataTransport/GDTCORLibrary/GDTCORDirectorySizeTracker.m +++ b/GoogleDataTransport/GDTCORLibrary/GDTCORDirectorySizeTracker.m @@ -69,7 +69,7 @@ - (void)resetCachedSize { - (GDTCORStorageSizeBytes)calculateDirectoryContentSize { NSArray *prefetchedProperties = @[ NSURLIsRegularFileKey, NSURLFileSizeKey ]; uint64_t totalBytes = 0; - NSURL *directoryURL = [NSURL URLWithString:self.directoryPath]; + NSURL *directoryURL = [NSURL fileURLWithPath:self.directoryPath]; NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtURL:directoryURL diff --git a/GoogleDataTransport/GDTCORTests/Unit/GDTCORDirectorySizeTrackerTests.m b/GoogleDataTransport/GDTCORTests/Unit/GDTCORDirectorySizeTrackerTests.m new file mode 100644 index 00000000000..901f8e3b7e5 --- /dev/null +++ b/GoogleDataTransport/GDTCORTests/Unit/GDTCORDirectorySizeTrackerTests.m @@ -0,0 +1,35 @@ +/* + * Copyright 2020 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#import + +#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORDirectorySizeTracker.h" + +@interface GDTCORDirectorySizeTrackerTests : XCTestCase + +@end + +@implementation GDTCORDirectorySizeTrackerTests + +- (void)testDirectoryContentSizeDoesNotCrashWhenDirectoryPathContainsWhitespaces { + NSString *pathWithSpaces = [NSTemporaryDirectory() stringByAppendingPathComponent:@"some dir"]; + GDTCORDirectorySizeTracker *tracker = + [[GDTCORDirectorySizeTracker alloc] initWithDirectoryPath:pathWithSpaces]; + + XCTAssertNoThrow([tracker directoryContentSize]); +} + +@end