Skip to content

Commit 38be2cc

Browse files
GDTCORDirectorySizeTracker: fix NSURL constructor (#6580)
* GDTCORDirectorySizeTracker: replace optional NSURL constructor with non-optional. * GDTCORDirectorySizeTracker tests for the issue * ./scripts/style.sh * changelog
1 parent 2311c36 commit 38be2cc

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

GoogleDataTransport/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
22
- Legacy pre Xcode 10 compatibility checks removed. (#6486)
3+
- `GDTCORDirectorySizeTracker` crash fixed. (#6540)
34

45
# v7.4.0
56
- Limit disk space consumed by GoogleDataTransport to store events. (#6365)

GoogleDataTransport/GDTCORLibrary/GDTCORDirectorySizeTracker.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ - (void)resetCachedSize {
6969
- (GDTCORStorageSizeBytes)calculateDirectoryContentSize {
7070
NSArray *prefetchedProperties = @[ NSURLIsRegularFileKey, NSURLFileSizeKey ];
7171
uint64_t totalBytes = 0;
72-
NSURL *directoryURL = [NSURL URLWithString:self.directoryPath];
72+
NSURL *directoryURL = [NSURL fileURLWithPath:self.directoryPath];
7373

7474
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
7575
enumeratorAtURL:directoryURL
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import <XCTest/XCTest.h>
18+
19+
#import "GoogleDataTransport/GDTCORLibrary/Internal/GDTCORDirectorySizeTracker.h"
20+
21+
@interface GDTCORDirectorySizeTrackerTests : XCTestCase
22+
23+
@end
24+
25+
@implementation GDTCORDirectorySizeTrackerTests
26+
27+
- (void)testDirectoryContentSizeDoesNotCrashWhenDirectoryPathContainsWhitespaces {
28+
NSString *pathWithSpaces = [NSTemporaryDirectory() stringByAppendingPathComponent:@"some dir"];
29+
GDTCORDirectorySizeTracker *tracker =
30+
[[GDTCORDirectorySizeTracker alloc] initWithDirectoryPath:pathWithSpaces];
31+
32+
XCTAssertNoThrow([tracker directoryContentSize]);
33+
}
34+
35+
@end

0 commit comments

Comments
 (0)