URLHostAllowedCharacterSet shouldn't include the & character
| Originator: | futuretap | ||
| Number: | rdar://24366292 | Date Originated: | 27-Jan-2016 01:15 PM |
| Status: | Closed/Behaves correctly | Resolved: | |
| Product: | iOS | Product Version: | 9.3 beta 1 |
| Classification: | Other Bug | Reproducible: | Always |
Summary: URLHostAllowedCharacterSet should only include these characters: "0-9a-zA-Z-.:[]" Specifically, it should not include the & character. Steps to Reproduce: (lldb) po [[NSCharacterSet URLHostAllowedCharacterSet] characterIsMember:[@"&" characterAtIndex:0]] Expected Results: NO Actual Results: YES Notes: I'm having a hard time finding an appropriate character set in order to URL-encode a complete URL. (I want to send a complete URL as a query parameter). In absence of a character set that includes just the "Unreserved Characters" according to RFC3986 (2.3), I thought URLHostAllowedCharacterSet would be the most suitable.
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!
Apple response
Engineering has provided the following feedback regarding this issue:
There are currently no plans to add an additional character set for your purposes.
However, it’s very simple to do it yourself.
We consider this issue closed.
My response
Thanks for your detailed answer and your suggestion to use NSURLComponents instead. I was expecting to be able to achieve the same using
-stringByAddingPercentEncodingWithAllowedCharacters:and an appropriate character set. Alas, such a character seems to not exist yet. So I suggest adding aURLQueryParameterAllowedCharacterSetthat excludes the "?", "&" and "=" in addition toURLQueryAllowedCharacterSet.My response
Thanks for your detailed answer and your suggestion to use NSURLComponents instead. I expected to be able to achieve the same using
-stringByAddingPercentEncodingWithAllowedCharactersand an appropriate character set. Alas, such a character seems to not exist yet. So I suggest adding aURLQueryParameterAllowedCharacterSetthat excludes the "?", "&" and "=" in addition to the characters inURLQueryAllowedCharacterSet.Apple response
Engineering has determined that this issue behaves as intended based on the following information:
The "&" character is in the sub-delims characters which are all allowed in a host in the reg-name form.
Entire URL strings cannot be percent-encoded unless you know what will be done with the encoded string.
If you’re trying to set the entire query component to a URL, you can use stringByAddingPercentEncodingWithAllowedCharacters with the URLQueryAllowedCharacterSet.
If you are trying to set the value of query name-value pair, you should just do this:
output:
The reverse is:
output: