diff --git a/CoreFoundation/NumberDate.subproj/CFTimeZone.c b/CoreFoundation/NumberDate.subproj/CFTimeZone.c index 541af2c303..2d27f8ba25 100644 --- a/CoreFoundation/NumberDate.subproj/CFTimeZone.c +++ b/CoreFoundation/NumberDate.subproj/CFTimeZone.c @@ -891,6 +891,7 @@ void CFTimeZoneSetDefault(CFTimeZoneRef tz) { } static CFDictionaryRef __CFTimeZoneCopyCompatibilityDictionary(void); +static Boolean __nameStringOK(CFStringRef name); CFArrayRef CFTimeZoneCopyKnownNames(void) { CFArrayRef tzs; @@ -906,7 +907,7 @@ CFArrayRef CFTimeZoneCopyKnownNames(void) { CFIndex idx; for (idx = CFArrayGetCount(list); idx--; ) { CFStringRef item = (CFStringRef)CFArrayGetValueAtIndex(list, idx); - if (CFDictionaryContainsKey(dict, item)) { + if (CFDictionaryContainsKey(dict, item) || !__nameStringOK(item)) { CFArrayRemoveValueAtIndex(list, idx); } } diff --git a/TestFoundation/TestTimeZone.swift b/TestFoundation/TestTimeZone.swift index e605fa03f1..aa7f238e55 100644 --- a/TestFoundation/TestTimeZone.swift +++ b/TestFoundation/TestTimeZone.swift @@ -28,6 +28,7 @@ class TestTimeZone: XCTestCase { // ("test_systemTimeZoneUsesSystemTime", test_systemTimeZoneUsesSystemTime), ("test_customMirror", test_tz_customMirror), + ("test_knownTimeZones", test_knownTimeZones), ] } @@ -189,4 +190,12 @@ class TestTimeZone: XCTestCase { XCTAssertNotNil(children["secondsFromGMT"]) XCTAssertNotNil(children["isDaylightSavingTime"]) } + + func test_knownTimeZones() { + let timeZones = TimeZone.knownTimeZoneIdentifiers.sorted() + XCTAssertTrue(timeZones.count > 0, "No known timezones") + for tz in timeZones { + XCTAssertNotNil(TimeZone(identifier: tz), "Cant instantiate valid timeZone: \(tz)") + } + } }