Wiki source code of TestJSEncoding

Last modified by Ludovic Dubost on 2009/04/26 22:27

Hide last authors
Ludovic Dubost 1.1 1 1 JS Encoding
2
3 <%
4
5 def getJSEncoded(String origtext) {
6 String text = origtext.replaceAll("\\\\", "\\\\");
7 text = text.replaceAll("'", "\\\\'");
8 text = text.replaceAll("\"", "\\\\x22");
9 return text;
10 }
11
Ludovic Dubost 2.1 12 text = getJSEncoded("c'est l'été \"test\"")
Ludovic Dubost 1.1 13 %>
Ludovic Dubost 3.1 14 {pre}
Ludovic Dubost 2.1 15 <input type="button" name="a" value="click" onclick="alert('$text');" />
Ludovic Dubost 3.1 16 {/pre}