You need to sign in to do that
Don't have an account?
HTMLENCODE from Apex code
Hello, I am trying to escape a rich textArea field to be shown in a visualforce page.
Right now, it's escaped using {!HTMLENCODE()}.
What I am trying to do is to allow a set of HTML tags, but only in some cases.
What I am looking for, ideally, is a way to call the HTMLENCODE function from apex code most of the time, and then implement my own escaping method for the cases that allow some HTML tags. What I am trying to avoid is re-implementing HtmlEncode in my classes.
So, the question is : is there a way to access the HTMLENCODE visualforce function from Apex code? If not, is there a functionally equivalent alternative I can reuse?
Any help will be appreciated, thanks!
Horacio
I believe what you're looking for is EncodingUtil.urlEncode().
I'm afraid that won't work, because I need to safely HTML encode the text, in order to show it in a page.
Anyhow, I ended up implementing my own HTMLEncode algorithm, dumb but safe, with the behaviour I needed.
Thanks for your help anyway!
In apex code you can do through string.replace(). In replace method the character is replaced by ASCII code.
Hope this helps.
http://code.google.com/p/force-dot-com-esapi/wiki/GettingStarted
Our port of the ESAPI provides Apex equivalents of JSENCODE, HTMLENCODE, JSINHTMLENCODE and URLENCODE functions.
usertext = ESAPI.encoder().SFDC_HTMLENCODE(unsafe_text);
Hello,
I am trying to do the same and want to perform HTML decode.
Any solution finalised for the same..?
Thanks in Advance,
Ray