### Question:
EscapeXssScript { public static String escape(String rawStr) { if (rawStr == null || rawStr.isEmpty()) return rawStr; rawStr = rawStr.replaceAll("&([A-Za-z1-4]{2,6});","&$1#"); rawStr = rawStr.replaceAll("&#([0-9A-Fa-f]{1,10});","&#$1#"); for (Character c : CHAR_ESCAPE_MAP.keySet()) rawStr = rawStr.replace(c.toString(), CHAR_ESCAPE_MAP.get(c)); rawStr = rawStr.replaceAll("&#([0-9A-Fa-f]{1,10})#","&#$1;"); rawStr = rawStr.replaceAll("&([A-Za-z1-4]{2,6})#","&$1;"); return rawStr; }  static String escape(String rawStr);  }### Answer:
@Test public void testEscape() { Assert.assertEquals("<script>alert; should be escaped as &lt;script&gt;alert&#059;", EscapeXssScript.escape("<script>alert;"), "&lt;script&gt;alert&#059;"); }
@Test public void testEscapeOfUnicodeChar() { Assert.assertEquals("<&#1071;> should be escaped as &lt;&#1071;&gt;", "&lt;&#1071;&gt;", EscapeXssScript.escape("<&#1071;>")); }
@Test public void testEscapeOfHTMLChar() { Assert.assertEquals("<&amp;&amp;&frac34;> should be escaped as &lt;&amp;&amp;&frac34;&gt;", "&lt;&amp;&amp;&frac34;&gt;", EscapeXssScript.escape("<&amp;&amp;&frac34;>")); }