I found something wrong with NSString’s stringByAddingPercentEscapeUsingEncoding method.
Take a look at this screenshot.
As you can see, I wanted to convert a clipDescription which holds AT&T Giants HD 1080i 50 LGOP.
When this was processed by calling stringByAddingPercentEscapesUsingEncoding:, it returned “AT&T%20Giants%20HD%201080i%2050%20LGOP”. So, the & is not percent escaped. When this one is handled by any XML handler, for example, tidy or xmllint, they complain that the string is malformed.
So, I had to write my own for percent escaping.
At first, I thought this was a bug, but thought twice. I guess this is just for different purpose.
For example, URL string can contain & character to be sent. Is it OK to send it just as it is? or should it be percent-escaped? I didn’t test it. But I noticed that many web site contained the & character not percent-escaped. So, probably this stringByAddingPercentEscapesUsingEncoding is for handling URL strings.
(ADDED : I noticed some people read this post from StackOverflow. So, I update this part not to confuse or not to give wrong impression. The web site URL containing & is for any passed parameter to the URL. When GET method is used, parameters are added using & characters. So, if that & is percent-escaped, it will mean totally different thing. So, in the method, it doesn’t percent-escape & characters. It could be better if Apple people named the message like URLstringByAddingPercentEscapesUsingEncoding for conveying its purpose more clearly.
However, it would be much nicer if they wrote some more explanation about where the method is used for, or something like that.