Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-6398] Ensure CFSTR() is CFRetained because it is not permanent on Linux. #1351

Merged
merged 1 commit into from Dec 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions CoreFoundation/URL.subproj/CFURLComponents.c
Expand Up @@ -63,7 +63,7 @@ struct __CFURLComponents {
static Boolean __CFURLComponentsEqual(CFTypeRef left, CFTypeRef right);

static CFStringRef __CFURLComponentsCopyDescription(CFTypeRef cf) {
return CFSTR("A really nice CFURLComponents object");
return CFRetain(CFSTR("A really nice CFURLComponents object"));
}

CF_SWIFT_EXPORT void __CFURLComponentsDeallocate(CFURLComponentsRef instance) {
Expand Down Expand Up @@ -1054,7 +1054,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
}
}
else {
nameString = CFSTR("");
nameString = (CFStringRef)CFRetain(CFSTR(""));
}
nameRange.location = kCFNotFound;
valueRange.location = idx + 1;
Expand All @@ -1076,7 +1076,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
}
}
else {
valueString = CFSTR("");
valueString = (CFStringRef)CFRetain(CFSTR(""));
}
CFStringRef name = CFSTR("name");
CFTypeRef keys[] = {name, CFSTR("value")};
Expand All @@ -1101,7 +1101,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
}
}
else {
nameString = CFSTR("");
nameString = (CFStringRef)CFRetain(CFSTR(""));
}
CFStringRef name = CFSTR("name");
CFTypeRef keys[] = {name};
Expand Down Expand Up @@ -1131,7 +1131,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
}
}
else {
valueString = CFSTR("");
valueString = (CFStringRef)CFRetain(CFSTR(""));
}
CFStringRef name = CFSTR("name");
CFTypeRef keys[] = {name, CFSTR("value")};
Expand All @@ -1155,7 +1155,7 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
}
}
else {
nameString = CFSTR("");
nameString = (CFStringRef)CFRetain(CFSTR(""));
}
CFStringRef name = CFSTR("name");
CFTypeRef keys[] = {name};
Expand Down
14 changes: 14 additions & 0 deletions TestFoundation/TestURL.swift
Expand Up @@ -525,6 +525,7 @@ class TestURL : XCTestCase {
class TestURLComponents : XCTestCase {
static var allTests: [(String, (TestURLComponents) -> () throws -> Void)] {
return [
("test_queryItems", test_queryItems),
("test_string", test_string),
("test_port", test_portSetter),
("test_url", test_url),
Expand All @@ -535,6 +536,19 @@ class TestURLComponents : XCTestCase {
]
}

func test_queryItems() {
let urlString = "http://localhost:8080/foo?bar=&bar=baz"
let url = URL(string: urlString)!

let components = URLComponents(url: url, resolvingAgainstBaseURL: false)

var query = [String: String]()
components?.queryItems?.forEach {
query[$0.name] = $0.value ?? ""
}
XCTAssertEqual(["bar": "baz"], query)
}

func test_string() {
for obj in getTestData()! {
let testDict = obj as! [String: Any]
Expand Down