@Test public void testEscapeHtml1() { String expected = "&lt;abc&gt;&amp;&quot;&#39;&#92;<br>\n"; String actual = EscapeUtils.escapeHtml("<abc>&\"'\\\r\n", true); System.out.println("* HTML1\n exp: [" + expected + "]\n act: [" + actual + "]"); assertThat(actual, equalTo(expected)); }
public static String escapeHtml(String s, boolean newline) { StringBuilder result = new StringBuilder(); Matcher matcher = HTML_RE.matcher(s); int index = 0; while (matcher.find(index)) { int start = matcher.start(); if (index < start) result.append(s, index, start); if (newline) { result.append(HTML_ESC_MAP.get(matcher.group())); } else { String specials = matcher.group(1); if (specials != null) result.append(HTML_ESC_MAP.get(specials)); else result.append('\n'); } index = matcher.end(); } if (index < s.length()) result.append(s, index, s.length()); return result.toString(); }
EscapeUtils { public static String escapeHtml(String s, boolean newline) { StringBuilder result = new StringBuilder(); Matcher matcher = HTML_RE.matcher(s); int index = 0; while (matcher.find(index)) { int start = matcher.start(); if (index < start) result.append(s, index, start); if (newline) { result.append(HTML_ESC_MAP.get(matcher.group())); } else { String specials = matcher.group(1); if (specials != null) result.append(HTML_ESC_MAP.get(specials)); else result.append('\n'); } index = matcher.end(); } if (index < s.length()) result.append(s, index, s.length()); return result.toString(); } }
EscapeUtils { public static String escapeHtml(String s, boolean newline) { StringBuilder result = new StringBuilder(); Matcher matcher = HTML_RE.matcher(s); int index = 0; while (matcher.find(index)) { int start = matcher.start(); if (index < start) result.append(s, index, start); if (newline) { result.append(HTML_ESC_MAP.get(matcher.group())); } else { String specials = matcher.group(1); if (specials != null) result.append(HTML_ESC_MAP.get(specials)); else result.append('\n'); } index = matcher.end(); } if (index < s.length()) result.append(s, index, s.length()); return result.toString(); } private  EscapeUtils(); }
EscapeUtils { public static String escapeHtml(String s, boolean newline) { StringBuilder result = new StringBuilder(); Matcher matcher = HTML_RE.matcher(s); int index = 0; while (matcher.find(index)) { int start = matcher.start(); if (index < start) result.append(s, index, start); if (newline) { result.append(HTML_ESC_MAP.get(matcher.group())); } else { String specials = matcher.group(1); if (specials != null) result.append(HTML_ESC_MAP.get(specials)); else result.append('\n'); } index = matcher.end(); } if (index < s.length()) result.append(s, index, s.length()); return result.toString(); } private  EscapeUtils(); static String escapeHtml(String s, boolean newline); static String encodeUri(String s); static String escapeJSString(String s); }
EscapeUtils { public static String escapeHtml(String s, boolean newline) { StringBuilder result = new StringBuilder(); Matcher matcher = HTML_RE.matcher(s); int index = 0; while (matcher.find(index)) { int start = matcher.start(); if (index < start) result.append(s, index, start); if (newline) { result.append(HTML_ESC_MAP.get(matcher.group())); } else { String specials = matcher.group(1); if (specials != null) result.append(HTML_ESC_MAP.get(specials)); else result.append('\n'); } index = matcher.end(); } if (index < s.length()) result.append(s, index, s.length()); return result.toString(); } private  EscapeUtils(); static String escapeHtml(String s, boolean newline); static String encodeUri(String s); static String escapeJSString(String s); static final Pattern HTML_RE; static final Map<String, String> HTML_ESC_MAP; }