Skip to content

Commit b45abfc

Browse files
committed
Workaround for overrealeased NSCFConstantString
1 parent 4c2dec5 commit b45abfc

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

CoreFoundation/URL.subproj/CFURLComponents.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,11 +556,11 @@ CF_EXPORT CFStringRef _CFURLComponentsCopyPath(CFURLComponentsRef components) {
556556
components->_pathComponentValid = true;
557557
}
558558
if (!components->_pathComponent) {
559-
result = CFSTR("");
559+
result = CFStringCreateCopy(kCFAllocatorSystemDefault, CFSTR(""));
560560
} else {
561561
result = _CFStringCreateByRemovingPercentEncoding(kCFAllocatorSystemDefault, components->_pathComponent);
562562
if (!result) {
563-
result = CFSTR("");
563+
result = CFStringCreateCopy(kCFAllocatorSystemDefault, CFSTR(""));
564564
}
565565
}
566566
__CFUnlock(&components->_lock);
@@ -745,7 +745,7 @@ CF_EXPORT CFStringRef _CFURLComponentsCopyPercentEncodedPath(CFURLComponentsRef
745745
result = components->_pathComponent ? CFRetain(components->_pathComponent) : NULL;
746746
__CFUnlock(&components->_lock);
747747

748-
if (!result) result = CFSTR("");
748+
if (!result) result = CFStringCreateCopy(kCFAllocatorSystemDefault, CFSTR(""));
749749

750750
return ( result );
751751
}

TestFoundation/TestURL.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,9 @@ class TestURLComponents : XCTestCase {
523523
("test_port", test_portSetter),
524524
("test_url", test_url),
525525
("test_copy", test_copy),
526-
("test_createURLWithComponents", test_createURLWithComponents)
526+
("test_createURLWithComponents", test_createURLWithComponents),
527+
("test_path", test_path),
528+
("test_percentEncodedPath", test_percentEncodedPath),
527529
]
528530
}
529531

@@ -617,4 +619,43 @@ class TestURLComponents : XCTestCase {
617619
XCTAssertEqual(urlComponents.queryItems?.count, 4)
618620
}
619621

622+
func test_path() {
623+
let c1 = URLComponents()
624+
XCTAssertEqual(c1.path, "")
625+
626+
let c2 = URLComponents(string: "http://swift.org")
627+
XCTAssertEqual(c2?.path, "")
628+
629+
let c3 = URLComponents(string: "http://swift.org/")
630+
XCTAssertEqual(c3?.path, "/")
631+
632+
let c4 = URLComponents(string: "http://swift.org/foo/bar")
633+
XCTAssertEqual(c4?.path, "/foo/bar")
634+
635+
let c5 = URLComponents(string: "http://swift.org:80/foo/bar")
636+
XCTAssertEqual(c5?.path, "/foo/bar")
637+
638+
let c6 = URLComponents(string: "http://swift.org:80/foo/b%20r")
639+
XCTAssertEqual(c6?.path, "/foo/b r")
640+
}
641+
642+
func test_percentEncodedPath() {
643+
let c1 = URLComponents()
644+
XCTAssertEqual(c1.percentEncodedPath, "")
645+
646+
let c2 = URLComponents(string: "http://swift.org")
647+
XCTAssertEqual(c2?.percentEncodedPath, "")
648+
649+
let c3 = URLComponents(string: "http://swift.org/")
650+
XCTAssertEqual(c3?.percentEncodedPath, "/")
651+
652+
let c4 = URLComponents(string: "http://swift.org/foo/bar")
653+
XCTAssertEqual(c4?.percentEncodedPath, "/foo/bar")
654+
655+
let c5 = URLComponents(string: "http://swift.org:80/foo/bar")
656+
XCTAssertEqual(c5?.percentEncodedPath, "/foo/bar")
657+
658+
let c6 = URLComponents(string: "http://swift.org:80/foo/b%20r")
659+
XCTAssertEqual(c6?.percentEncodedPath, "/foo/b%20r")
660+
}
620661
}

0 commit comments

Comments
 (0)