function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mary.taglermary.tagler 

What specific characters is JSENCODE handling?

I've reviewed the developer and help site documentation and they say the exact same thing:
Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe (').
That's great, but I'd like to know which specific characters JSENCODE and JSINHTMLENCODE handle.

If that's not clear, I want a detailed list.
 
VinayVinay (Salesforce Developers) 
Hi Mary,

JSENCODE:
Encodes text and merge field values for use in JavaScript by inserting escape characters, such as a backslash (\), before unsafe JavaScript characters, such as the apostrophe (').
JSINHTMLENCODE:
Encodes text and merge field values for use in JavaScript inside HTML tags by replacing characters that are reserved in HTML with HTML entity equivalents and inserting escape characters before unsafe JavaScript characters. JSINHTMLENCODE(someValue) is a convenience function that is equivalent to JSENCODE(HTMLENCODE((someValue)). That is, JSINHTMLENCODE first encodes someValue with HTMLENCODE, and then encodes the result with JSENCODE.

Check below references for more details.
https://www.infallibletechie.com/2016/12/platform-encoding-in-visualforce.html
http://jessealtman.com/2017/04/interesting-interaction-between-inlinehelptext-and-jsinhtmlencode/
https://salesforcethinkers.home.blog/2020/04/21/text-formula-operators-and-functions-in-salesforce/
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_functions.htm

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
mary.taglermary.tagler
Thanks for the resources, unfortunately that doesn't get to the heart of my question. I need a list of all of those characters. I'm using JSENCODE around a text field to get it until JSON format to post to Slack using the Unofficialsf Slack Actions action. What I'm seeing in my flow error messages is that it's escaping asterisk aka *. The problem is it changes * to \* . The problem with that is \ is unhandled by JSON so if a post has * , it fails to post. We tried wrapping JSENCODE in SUBSTITUTE , but it won't allow it. It doesn't accept the \. Everywhere I've consulted * is not a reserved JS character.

If I have a complete list, I can hack a formula using lots of SUBSTITUTE functions if I have to.
VinayVinay (Salesforce Developers) 
As per my understanding, I don't think we have complete list apart for above references will add more details if I find any.

Thanks,
Evan PonterEvan Ponter
Here's what I found after some testing:
* is changed to \*
\ is changed to \\
' is changed to \'
" is changed to \"
< is changed to \u003C
> is changed to \u003E
mary.taglermary.tagler
Thanks Evan. I wasn't expecting * to be handled based on the resource I was using of reserved characters. I was trying to get around using multiple nested substitutes, but will likely have to because I need * not to be handled. I really feel like the documentation should call this out specifically rather than just generalize.