Skip to content

Commit 08ca2d1

Browse files
parkeraAnton Pogonets
authored and
Anton Pogonets
committed
[SR-6398] Ensure CFSTR() is CFRetained because it is not permanent on Linux. (swiftlang#1351)
1 parent 002557d commit 08ca2d1

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

CoreFoundation/URL.subproj/CFURLComponents.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct __CFURLComponents {
6363
static Boolean __CFURLComponentsEqual(CFTypeRef left, CFTypeRef right);
6464

6565
static CFStringRef __CFURLComponentsCopyDescription(CFTypeRef cf) {
66-
return CFSTR("A really nice CFURLComponents object");
66+
return CFRetain(CFSTR("A really nice CFURLComponents object"));
6767
}
6868

6969
CF_SWIFT_EXPORT void __CFURLComponentsDeallocate(CFURLComponentsRef instance) {
@@ -1054,7 +1054,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
10541054
}
10551055
}
10561056
else {
1057-
nameString = CFSTR("");
1057+
nameString = (CFStringRef)CFRetain(CFSTR(""));
10581058
}
10591059
nameRange.location = kCFNotFound;
10601060
valueRange.location = idx + 1;
@@ -1076,7 +1076,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
10761076
}
10771077
}
10781078
else {
1079-
valueString = CFSTR("");
1079+
valueString = (CFStringRef)CFRetain(CFSTR(""));
10801080
}
10811081
CFStringRef name = CFSTR("name");
10821082
CFTypeRef keys[] = {name, CFSTR("value")};
@@ -1101,7 +1101,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
11011101
}
11021102
}
11031103
else {
1104-
nameString = CFSTR("");
1104+
nameString = (CFStringRef)CFRetain(CFSTR(""));
11051105
}
11061106
CFStringRef name = CFSTR("name");
11071107
CFTypeRef keys[] = {name};
@@ -1131,7 +1131,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
11311131
}
11321132
}
11331133
else {
1134-
valueString = CFSTR("");
1134+
valueString = (CFStringRef)CFRetain(CFSTR(""));
11351135
}
11361136
CFStringRef name = CFSTR("name");
11371137
CFTypeRef keys[] = {name, CFSTR("value")};
@@ -1155,7 +1155,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
11551155
}
11561156
}
11571157
else {
1158-
nameString = CFSTR("");
1158+
nameString = (CFStringRef)CFRetain(CFSTR(""));
11591159
}
11601160
CFStringRef name = CFSTR("name");
11611161
CFTypeRef keys[] = {name};

TestFoundation/TestURL.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ class TestURL : XCTestCase {
519519
class TestURLComponents : XCTestCase {
520520
static var allTests: [(String, (TestURLComponents) -> () throws -> Void)] {
521521
return [
522+
("test_queryItems", test_queryItems),
522523
("test_string", test_string),
523524
("test_port", test_portSetter),
524525
("test_url", test_url),
@@ -527,6 +528,19 @@ class TestURLComponents : XCTestCase {
527528
]
528529
}
529530

531+
func test_queryItems() {
532+
let urlString = "http://localhost:8080/foo?bar=&bar=baz"
533+
let url = URL(string: urlString)!
534+
535+
let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
536+
537+
var query = [String: String]()
538+
components?.queryItems?.forEach {
539+
query[$0.name] = $0.value ?? ""
540+
}
541+
XCTAssertEqual(["bar": "baz"], query)
542+
}
543+
530544
func test_string() {
531545
for obj in getTestData()! {
532546
let testDict = obj as! [String: Any]

0 commit comments

Comments
 (0)