2

My CodenameOne app needs to pass HTML code to HTML elements inside a BrowserComponent with Javascript, so characters have to be escaped more than one time, they have to be encoded in fact.

I need something like TextUtils.htmlEncode().

In Codename it seems to be HTMLUtils but is deprecated, and I am not sure there is the equivalent method.

So what is the equivalent of TextUtils.htmlEncode() in CodenameOne?

AleksanderGD
  • 414
  • 5
  • 10
P5music
  • 3,197
  • 2
  • 32
  • 81

1 Answers1

1

In fact I just need to manage double quotes for the srcdoc parameter of iFrames, so if I am not wrong the solution is to replace

" 

with

\"

In Java:

String htmlText=originalHTMLToEmbed.replace("\"","\\\"");

I tried it and it works.

If more levels are involved in HTML, they are already escaped, so occurrences of

\\\" 

(and so on) are possible to be found in the final string.

P5music
  • 3,197
  • 2
  • 32
  • 81