MCPcopy Create free account
hub / github.com/apache/tomcat / htmlElementContent

Method htmlElementContent

java/org/apache/tomcat/util/security/Escape.java:42–69  ·  view source on GitHub ↗

Escape content for use in HTML. This escaping is suitable for the following uses: Element content when the escaped data will be placed directly inside tags such as <p>, <td> etc. Attribute values when the attribute value is quoted with " or '. @par

(String content)

Source from the content-addressed store, hash-verified

40 * @return The escaped content or {@code null} if the content was {@code null}
41 */
42 public static String htmlElementContent(String content) {
43 if (content == null) {
44 return null;
45 }
46
47 StringBuilder sb = new StringBuilder();
48
49 for (int i = 0; i < content.length(); i++) {
50 char c = content.charAt(i);
51 if (c == '<') {
52 sb.append("&lt;");
53 } else if (c == '>') {
54 sb.append("&gt;");
55 } else if (c == '\'') {
56 sb.append("&#39;");
57 } else if (c == '&') {
58 sb.append("&amp;");
59 } else if (c == '"') {
60 sb.append("&quot;");
61 } else if (c == '/') {
62 sb.append("&#47;");
63 } else {
64 sb.append(c);
65 }
66 }
67
68 return (sb.length() > content.length()) ? sb.toString() : content;
69 }
70
71
72 /**

Callers 15

testHtmlContentMethod · 0.95
testHtmlContentObjectMethod · 0.95
handleMissingResourceMethod · 0.95
reportMethod · 0.95
sendRedirectMethod · 0.95
encodeMethod · 0.95
renderXmlMethod · 0.95
renderHtmlMethod · 0.95
sessionsMethod · 0.95

Calls 4

lengthMethod · 0.80
charAtMethod · 0.80
toStringMethod · 0.65
appendMethod · 0.45

Tested by 5

testHtmlContentMethod · 0.76
testHtmlContentObjectMethod · 0.76