CFURLCreateStringByAddingPercentEscapes documentation states incorrect RFC spec

Originator:christian.noon
Number:rdar://21220820 Date Originated:03-Jun-2015 08:35 AM
Status:Closed Resolved:13-Jul-2016 07:56 PM
Product:Documentation Product Version:Xcode 6.3.2
Classification:Serious Bug Reproducible:Always
 
Summary:
The documentation for `CFURLCreateStringByAddingPercentEscapes` states:

> The characters escaped are all characters that are not legal URL characters (based on RFC 3986), plus any characters in legalURLCharactersToBeEscaped, less any characters in charactersToLeaveUnescaped. To simply correct any non-URL characters in an otherwise correct URL string, pass NULL for the allocator, charactersToLeaveEscaped, and legalURLCharactersToBeEscaped parameters, and kCFStringEncodingUTF8 as the encoding parameter.

- https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFURLRef/#//apple_ref/c/func/CFURLCreateStringByAddingPercentEscapes

The header documentation states the following:

> Creates a copy or originalString, replacing certain characters with the equivalent percent escape sequence based on the encoding specified. If the originalString does not need to be modified (no percent escape sequences are missing), may retain and return originalString. If you are uncertain of the correct encoding, you should use UTF-8, which is the encoding designated by RFC 2396 as the correct encoding for use in URLs.  The characters so escaped are all characters that are not legal URL characters (based on RFC 2396), plus any characters in legalURLCharactersToBeEscaped, less any characters in charactersToLeaveUnescaped.

As you can see, the public documentation believes the percent escaping follows RFC 3986 while the header claims to follow RFC 2396. Though various tests, it has been observed that `CFURLCreateStringByAddingPercentEscapes` does follow RFC 2396 as stated in the header. The documentation should be updated to reflect this fact.

Here is a chunk of Swift code to demonstrate the issue.

```
func escape(string: String) -> String {
    return CFURLCreateStringByAddingPercentEscapes(nil, string, nil, nil, CFStringBuiltInEncodings.UTF8.rawValue) as String
}

let asciiCharacters = [
    " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", ":",
    ";", "<", "=", ">", "?", "@", "[", "\\", "]", "^", "_", "`", "{", "|", "}", "~",
    "0123456789", "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
]

asciiCharacters.map { println("\"\($0)\" = \"\(escape($0))\"") }

let nonLegalCharacters = " \"#%<>[]\\^`{}|"
```

The following characters are considered "legal" in RFC 3986.

- "[]#"

Steps to Reproduce:


Expected Results:


Actual Results:


Version:


Notes:


Configuration:


Attachments:

Resolved in new documentation: 

* https://developer.apple.com/reference/corefoundation/1542665-cfurlcreatestringbyaddingpercent

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!