Skip to content

Commit 0b807eb

Browse files
committed
[SR-3329] URLQueryItems are not getting encoded in to the URL
1 parent 11c2169 commit 0b807eb

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

CoreFoundation/URL.subproj/CFURLComponents.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
10731073
else {
10741074
valueString = CFSTR("");
10751075
}
1076-
CFTypeRef keys[] = {CFSTR("name"), CFSTR("value")};
1076+
CFStringRef name = CFSTR("name");
1077+
CFTypeRef keys[] = {name, CFSTR("value")};
10771078
CFTypeRef values[] = {nameString, valueString};
10781079
CFDictionaryRef entry = CFDictionaryCreate(kCFAllocatorSystemDefault, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
10791080
CFArrayAppendValue(intermediateResult, entry);
@@ -1097,7 +1098,8 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
10971098
else {
10981099
nameString = CFSTR("");
10991100
}
1100-
CFTypeRef keys[] = {CFSTR("name")};
1101+
CFStringRef name = CFSTR("name");
1102+
CFTypeRef keys[] = {name};
11011103
CFTypeRef values[] = {nameString};
11021104
CFDictionaryRef entry = CFDictionaryCreate(kCFAllocatorSystemDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
11031105
CFArrayAppendValue(intermediateResult, entry);
@@ -1126,7 +1128,8 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
11261128
else {
11271129
valueString = CFSTR("");
11281130
}
1129-
CFTypeRef keys[] = {CFSTR("name"), CFSTR("value")};
1131+
CFStringRef name = CFSTR("name");
1132+
CFTypeRef keys[] = {name, CFSTR("value")};
11301133
CFTypeRef values[] = {nameString, valueString};
11311134
CFDictionaryRef entry = CFDictionaryCreate(kCFAllocatorSystemDefault, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
11321135
CFArrayAppendValue(intermediateResult, entry);
@@ -1148,7 +1151,8 @@ CF_EXPORT CFArrayRef _CFURLComponentsCopyQueryItems(CFURLComponentsRef component
11481151
else {
11491152
nameString = CFSTR("");
11501153
}
1151-
CFTypeRef keys[] = {CFSTR("name")};
1154+
CFStringRef name = CFSTR("name");
1155+
CFTypeRef keys[] = {name};
11521156
CFTypeRef values[] = {nameString};
11531157
CFDictionaryRef entry = CFDictionaryCreate(kCFAllocatorSystemDefault, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
11541158
CFArrayAppendValue(intermediateResult, entry);
@@ -1206,7 +1210,7 @@ CF_EXPORT void _CFURLComponentsSetQueryItems(CFURLComponentsRef components, CFAr
12061210
chars[0] = '=';
12071211
CFStringAppendCharactersToAppendBuffer(&buf, chars, 1);
12081212
CFStringRef stringWithPercentEncoding = _CFStringCreateByAddingPercentEncodingWithAllowedCharacters(kCFAllocatorSystemDefault, value, queryNameValueAllowed);
1209-
CFStringAppendStringToAppendBuffer(&buf, value);
1213+
CFStringAppendStringToAppendBuffer(&buf, stringWithPercentEncoding);
12101214
CFRelease(stringWithPercentEncoding);
12111215
}
12121216
// else the query item string will be simply "name"

TestFoundation/TestNSURL.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ class TestNSURLComponents : XCTestCase {
421421
("test_string", test_string),
422422
("test_port", test_portSetter),
423423
("test_url", test_url),
424-
("test_copy", test_copy)
424+
("test_copy", test_copy),
425+
("test_createURLWithComponents", test_createURLWithComponents)
425426
]
426427
}
427428

@@ -499,4 +500,20 @@ class TestNSURLComponents : XCTestCase {
499500
/* Assert that NSURLComponents.copy is actually a copy of NSURLComponents */
500501
XCTAssertTrue(copy.isEqual(urlComponent))
501502
}
503+
504+
func test_createURLWithComponents() {
505+
let urlComponents = NSURLComponents()
506+
urlComponents.scheme = "https";
507+
urlComponents.host = "com.test.swift";
508+
urlComponents.path = "/test/path";
509+
let date = Date()
510+
let query1 = URLQueryItem(name: "date", value: date.description)
511+
let query2 = URLQueryItem(name: "simpleDict", value: "false")
512+
let query3 = URLQueryItem(name: "checkTest", value: "false")
513+
let query4 = URLQueryItem(name: "someKey", value: "afsdjhfgsdkf^fhdjgf")
514+
urlComponents.queryItems = [query1, query2, query3, query4]
515+
XCTAssertNotNil(urlComponents.url?.query)
516+
XCTAssertEqual(urlComponents.queryItems?.count, 4)
517+
}
518+
502519
}

0 commit comments

Comments
 (0)