Have you ever had to escape a character this many times?
The past week I've found a new record while calling a super-quirky API: 12 escape characters!
This API required all that to accept double quotes and new lines in text from a callout within Salesforce.
Here is how:
1️⃣ one escape to indicate an escaped double quote - /"
❎2️⃣ double that because the API stored it in a string and to keep the double quote escaped - //"
❎2️⃣ double again because the API has another internal string conversion - ////"
➕1️⃣ another escape because the payload is within a GraphQL request - //////" (6 so far)
❎2️⃣ double the previous 6 escapes because the payload is contained in an Apex string.
Total: 12 escape characters.
Another quirk: users were pasting some weird characters from some other system so I had to use some Regex idioms to prevent them.
p{L} = matches all letters in any language
p{S} = matches all symbols
p{N} = matches all numbers
p{P} = matches all punctuation
