Skip to content

Commit bfa81ef

Browse files
committed
Merge pull request #253 from brownleej/url-encoding-fix
Adds nullability annotations to _CFStringCreateByRemovingPercentEncoding
2 parents 46a5331 + 913c8df commit bfa81ef

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

CoreFoundation/URL.subproj/CFURLComponents.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ CF_EXPORT CFRange _CFURLComponentsGetRangeOfQuery(CFURLComponentsRef components)
8989
CF_EXPORT CFRange _CFURLComponentsGetRangeOfFragment(CFURLComponentsRef components);
9090

9191
CF_EXPORT CFStringRef _CFStringCreateByAddingPercentEncodingWithAllowedCharacters(CFAllocatorRef alloc, CFStringRef string, CFCharacterSetRef allowedCharacters);
92-
CF_EXPORT CFStringRef _CFStringCreateByRemovingPercentEncoding(CFAllocatorRef alloc, CFStringRef string);
92+
CF_EXPORT CFStringRef _Nullable _CFStringCreateByRemovingPercentEncoding(CFAllocatorRef alloc, CFStringRef string);
9393

9494
// These return singletons
9595
CF_EXPORT CFCharacterSetRef _CFURLComponentsGetURLUserAllowedCharacterSet();

Foundation/NSURL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ extension NSString {
445445

446446
// Returns a new string made from the receiver by replacing all percent encoded sequences with the matching UTF-8 characters.
447447
public var stringByRemovingPercentEncoding: String? {
448-
return _CFStringCreateByRemovingPercentEncoding(kCFAllocatorSystemDefault, self._cfObject)._swiftObject
448+
return _CFStringCreateByRemovingPercentEncoding(kCFAllocatorSystemDefault, self._cfObject)?._swiftObject
449449
}
450450
}
451451

TestFoundation/TestNSString.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class TestNSString : XCTestCase {
7777
("test_stringByResolvingSymlinksInPath", test_stringByResolvingSymlinksInPath),
7878
("test_stringByExpandingTildeInPath", test_stringByExpandingTildeInPath),
7979
("test_stringByStandardizingPath", test_stringByStandardizingPath),
80+
("test_stringByRemovingPercentEncoding", test_stringByRemovingPercentEncoding),
8081
("test_ExternalRepresentation", test_ExternalRepresentation),
8182
("test_mutableStringConstructor", test_mutableStringConstructor),
8283
("test_PrefixSuffix", test_PrefixSuffix),
@@ -824,6 +825,13 @@ class TestNSString : XCTestCase {
824825
XCTAssertEqual(result, path.bridge(), "parent links could not be resolved for relative paths")
825826
}
826827
}
828+
829+
func test_stringByRemovingPercentEncoding() {
830+
let s1 = "a%20b".stringByRemovingPercentEncoding
831+
XCTAssertEqual(s1, "a b")
832+
let s2 = "a%1 b".stringByRemovingPercentEncoding
833+
XCTAssertNil(s2, "returns nil for a string with an invalid percent encoding")
834+
}
827835

828836
func test_ExternalRepresentation() {
829837
// Ensure NSString can be used to create an external data representation

0 commit comments

Comments
 (0)