Post

2 followers Follow
0
Avatar

Replace ampersand by html safe code problem

I have a simple calculation field, which aims to replace all special characters in a string.

This works :

"Chip & Dale".replace(/</g,"&lt;");
"Chip & Dale".replace(/>/g,"&gt;");
"Chip & Dale".replace(/\'/g,"&apos;");
"Chip & Dale".replace(/"/g,"&quot;");

but it doesn't work for

"Chip & Dale".replace(/&/g,"&amp;");

=> No matter what I do, Podio refuses to transform "&" into "&amp;" in the end result (it DOES however show &amp; in the calculation preview)


Does Podio overrule this somehow? Anybody has an idea on how to force this?

Mike Demunter

Please sign in to leave a comment.

1 comment

1
Avatar

Hi Mike,

first: It also doesn't work for the 4 others. If you replace <>'" by their entity they will be displayed as <>"' in calculation fields. 
What you need is a zero-white-space before the semicolon. 
You can either copy a zero-white-space to your clipboard (some websites offer that, just seach for it) and paste it before the semicolon or after the & -  or you use an encoded UTF:

"Chip & Dale".replace(/&/g,"&amp​\u200B;")

In Globiflow you can use the Unicode as HTML encoded  &#8203;  to update e.g a multiline text field (but it works only after the &)

str_replace("&","&&#8203;amp;​​","Chip & Dale")

Rainer

Rainer Grabowski 1 vote