I\'m developing an application for the iPhone that has inApp-mail sending capabilities. So far so good, but now I want to avoid html-injections as some parts of the mail are
I'm expanding @Markus answer, because my case is i'm sending JSON string, so i need to added some escape, these are my function :
note : the exception reference from w3schools. https://www.w3schools.com/tags/ref_urlencode.asp
- (NSString*)convertStringToHTMLEscape:(NSString*)stringContent
{
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"{" withString:@"%7B"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"}" withString:@"%7D"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"[" withString:@"%5B"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"]" withString:@"%5D"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"\"" withString:@"%22"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"\\" withString:@"%5C"];
stringContent = [stringContent stringByReplacingOccurrencesOfString:@"/" withString:@"%2F"];
return stringContent;
}