Could there be any issues with doing a double NSUTF8StringEncoding on a NSString?

116 Views Asked by At

So I am making a POST call to my server with the following code:

NSCharacterSet *set = [NSCharacterSet URLQueryAllowedCharacterSet];
NSString *POSTencoded = [POSTdata stringByAddingPercentEncodingWithAllowedCharacters:set];
NSData *postData = [POSTencoded dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
[request setHTTPBody:postData];

The function stringByAddingPercentEncodingWithAllowedCharacters: automatically uses UTF-8 encoding on my string, according to Apple's documentation. I am not sure if it's a lossy conversion or not though.

Then on the next line I encode the data again, making sure I set allowLossyConversion: to YES.

Questions:

  1. Does stringByAddingPercentEncodingWithAllowedCharacters: have lossy conversion set to YES or NO?

  2. Does double-encoding with UTF8 have the potential to convert some of my characters in unforeseen ways?

0

There are 0 best solutions below