4343 * Encode -- fluent interface for contextual encoding. Example usage in a JSP:
4444 *
4545 * <pre>
46- * <input value="<%=Encode.forHtml(value)%> " />
46+ * <input value="<%=Encode.forHtml(value)%> " />
4747 * </pre>
4848 *
4949 * <p>There are two versions of each contextual encoding method. The first
@@ -71,15 +71,15 @@ private Encode() {}
7171 * bytes or are writing a framework that utilizes this
7272 * package.</p>
7373 *
74- * <h5 >Example JSP Usage</h5 >
74+ * <b >Example JSP Usage</b >
7575 * <pre>
76- * <div>& lt;%=Encode.forHtml(unsafeData)%>& lt;/div>
76+ * <div>& lt;%=Encode.forHtml(unsafeData)%>& lt;/div>
7777 *
78- * <input value="<%=Encode.forHtml(unsafeData)%> " />
78+ * <input value="<%=Encode.forHtml(unsafeData)%> " />
7979 * </pre>
8080 *
81- * <h5>Encoding Table</h5 >
82- * <table border="0" >
81+ * <table border="0" summary="Shows the input and results of encoding" >
82+ * <caption><b>Encoding Table</b></caption >
8383 * <thead>
8484 * <tr bgcolor="#ccf">
8585 * <th align="left">Input</th>
@@ -110,7 +110,7 @@ private Encode() {}
110110 * </tbody>
111111 * </table>
112112 *
113- * <h5 >Additional Notes</h5 >
113+ * <b >Additional Notes</b >
114114 * <ul>
115115 *
116116 * <li>The encoding of the greater-than sign ({@code >}) is not
@@ -160,12 +160,12 @@ public static void forHtml(Writer out, String input) throws IOException {
160160 * HTML attributes. Use either forHtml or forHtmlAttribute for those
161161 * methods.</p>
162162 *
163- * <h5 >Example JSP Usage</h5 >
163+ * <b >Example JSP Usage</b >
164164 * <pre>
165- * <div>& lt;%=Encode.forHtmlContent(unsafeData)%>& lt;/div>
165+ * <div>& lt;%=Encode.forHtmlContent(unsafeData)%>& lt;/div>
166166 * </pre>
167- * <h5>Encoding Table</h5 >
168- * <table border="0" >
167+ * <table border="0" summary="Shows the input and results of encoding" >
168+ * <caption><b>Encoding Table</b></caption >
169169 * <thead>
170170 * <tr bgcolor="#ccf">
171171 * <th align="left">Input</th>
@@ -188,7 +188,7 @@ public static void forHtml(Writer out, String input) throws IOException {
188188 * </tbody>
189189 * </table>
190190 *
191- * <h5 >Additional Notes</h5 >
191+ * <b >Additional Notes</b >
192192 * <ul>
193193 *
194194 * <li>Single-quote character ({@code '}) and double-quote
@@ -238,13 +238,13 @@ public static void forHtmlContent(Writer out, String input)
238238 /**
239239 * <p>This method encodes for HTML text attributes.</p>
240240 *
241- * <h5 >Example JSP Usage</h5 >
241+ * <b >Example JSP Usage</b >
242242 * <pre>
243- * <div>& lt;%=Encode.forHtml(unsafeData)%>& lt;/div>
243+ * <div>& lt;%=Encode.forHtml(unsafeData)%>& lt;/div>
244244 * </pre>
245245 *
246- * <h5>Encoding Table</h5 >
247- * <table border="0" >
246+ * <table border="0" summary="Shows the input and results of encoding" >
247+ * <caption><b>Encoding Table</b></caption >
248248 * <thead>
249249 * <tr bgcolor="#ccf">
250250 * <th align="left">Input</th>
@@ -271,7 +271,7 @@ public static void forHtmlContent(Writer out, String input)
271271 * </tbody>
272272 * </table>
273273 *
274- * <h5 >Additional Notes</h5 >
274+ * <b >Additional Notes</b >
275275 * <ul>
276276 *
277277 * <li>Both the single-quote character ({@code '}) and the
@@ -339,13 +339,13 @@ public static void forHtmlAttribute(Writer out, String input)
339339 * attempt has been made to optimize this encoding, though it is
340340 * still probably faster than other encoding libraries.</p>
341341 *
342- * <h5 >Example JSP Usage</h5 >
342+ * <b >Example JSP Usage</b >
343343 * <pre>
344- * <input value=<%=Encode.forHtmlUnquotedAttribute(input)%> >
344+ * <input value=<%=Encode.forHtmlUnquotedAttribute(input)%> >
345345 * </pre>
346346 *
347- * <h5>Encoding Table</h5 >
348- * <table border="0" >
347+ * <table border="0" summary="Shows the input and results of encoding" >
348+ * <caption><b>Encoding Table</b></caption >
349349 * <thead>
350350 * <tr bgcolor="#ccf">
351351 * <th align="left">Input</th>
@@ -372,7 +372,7 @@ public static void forHtmlAttribute(Writer out, String input)
372372 * </tbody>
373373 * </table>
374374 *
375- * <h5 >Additional Notes</h5 >
375+ * <b >Additional Notes</b >
376376 * <ul>
377377 *
378378 * <li>The following characters are <i>not</i> encoded:
@@ -436,16 +436,16 @@ public static void forHtmlUnquotedAttribute(Writer out, String input)
436436 * characters. It is safe for use in both style blocks and attributes in
437437 * HTML.
438438 *
439- * <h5 >Example JSP Usage</h5 >
439+ * <b >Example JSP Usage</b >
440440 * <pre>
441- * <div style="background: url('<=Encode.forCssString(...)%> ');">
441+ * <div style="background: url('<=Encode.forCssString(...)%> ');">
442442 *
443- * <style type="text/css">
444- * background: url('<%=Encode.forCssString(...)%> ');
445- * </style>
443+ * <style type="text/css">
444+ * background: url('<%=Encode.forCssString(...)%> ');
445+ * </style>
446446 * </pre>
447447 *
448- * <h5 >Encoding Notes</h5 >
448+ * <b >Encoding Notes</b >
449449 * <ul>
450450 *
451451 * <li>The following characters are encoded using hexidecimal
@@ -515,15 +515,15 @@ public static void forCssString(Writer out, String input)
515515 * itself. The caller should insure that the URL is safe for embedding
516516 * (e.g. input validation) by other means.
517517 *
518- * <h5 >Example JSP Usage</h5 >
518+ * <b >Example JSP Usage</b >
519519 * <pre>
520- * <div style="background:url(<=Encode.forCssUrl(...)%> );">
520+ * <div style="background:url(<=Encode.forCssUrl(...)%> );">
521521 *
522- * <style type="text/css">
523- * background: url(<%=Encode.forCssUrl(...)%> );
524- * </style>
522+ * <style type="text/css">
523+ * background: url(<%=Encode.forCssUrl(...)%> );
524+ * </style>
525525 * </pre>
526- * <h5 >Encoding Notes</h5 >
526+ * <b >Encoding Notes</b >
527527 * <ul>
528528 *
529529 * <li>The following characters are encoded using hexidecimal
@@ -592,15 +592,15 @@ public static void forCssUrl(Writer out, String input)
592592 * example a "javascript:" URL provided by a malicious user would be
593593 * "properly" escaped, and still execute.
594594 *
595- * <h5 >Encoding Table</h5 >
595+ * <b >Encoding Table</b >
596596 * <p>The following characters are <i>not</i> encoded:</p>
597597 * <pre>
598- * U+20: ! # $ & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; = ?
598+ * U+20: ! # $ & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; = ?
599599 * U+40: @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ ] _
600600 * U+60: a b c d e f g h i j k l m n o p q r s t u v w x y z ~
601601 * </pre>
602602 *
603- * <h5 >Encoding Notes</h5 >
603+ * <b >Encoding Notes</b >
604604 * <ul>
605605 *
606606 * <li>The single-quote character({@code '}) <b>is not encoded</b>.</li>
@@ -657,20 +657,20 @@ public static void forCssUrl(Writer out, String input)
657657 * interpreted as part of another component.
658658 *
659659 * <pre>
660- * <a href="http://www.owasp.org/<%=Encode.forUriComponent(...)%> ?query#fragment">
660+ * <a href="http://www.owasp.org/<%=Encode.forUriComponent(...)%> ?query#fragment">
661661 *
662- * <a href="/search?value=<%=Encode.forUriComponent(...)%>& order=1#top">
662+ * <a href="/search?value=<%=Encode.forUriComponent(...)%>& order=1#top">
663663 * </pre>
664664 *
665- * <h5 >Encoding Table</h5 >
665+ * <b >Encoding Table</b >
666666 * <p>The following characters are <i>not</i> encoded:</p>
667667 * <pre>
668668 * U+20: - . 0 1 2 3 4 5 6 7 8 9
669669 * U+40: @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _
670670 * U+60: a b c d e f g h i j k l m n o p q r s t u v w x y z ~
671671 * </pre>
672672 *
673- * <h5 >Encoding Notes</h5 >
673+ * <b >Encoding Notes</b >
674674 * <ul>
675675 *
676676 * <li>Unlike {@link #forUri(String)} this method is safe to be
@@ -810,10 +810,10 @@ public static void forXmlAttribute(Writer out, String input)
810810 * caller will need to come up with their own encode/decode system.</p>
811811 *
812812 * <pre>
813- * out.println("<?xml version='1.0'?> ");
814- * out.println("<data> ");
815- * out.println("&; lt;!-- "+Encode.forXmlComment(comment)+" --> ");
816- * out.println("</data> ");
813+ * out.println("<?xml version='1.0'?> ");
814+ * out.println("<data> ");
815+ * out.println("<!-- "+Encode.forXmlComment(comment)+" --> ");
816+ * out.println("</data> ");
817817 * </pre>
818818 *
819819 * @param input the input to encode
@@ -846,7 +846,7 @@ public static void forXmlComment(Writer out, String input)
846846 * provide the CDATA section boundaries.
847847 *
848848 * <pre>
849- * <xml-data>& lt;![CDATA[<%=Encode.forCDATA(...)%>]]>& lt;/xml-data>
849+ * <xml-data>& lt;![CDATA[<%=Encode.forCDATA(...)%>]]>& lt;/xml-data>
850850 * </pre>
851851 *
852852 * @param input the input to encode
@@ -920,16 +920,16 @@ public static void forJava(Writer out, String input)
920920 * are writing a framework on top of this library, it is recommend
921921 * that you use this method over the others.</p>
922922 *
923- * <h5 >Example JSP Usage:</h5 >
923+ * <b >Example JSP Usage:</b >
924924 * <pre>
925- * <button onclick="alert('<%=Encode.forJavaScript(data)%> ');">
926- * <script type="text/javascript">
927- * var data = "<%=Encode.forJavaScript(data)%> ";
928- * </script>
925+ * <button onclick="alert('<%=Encode.forJavaScript(data)%> ');">
926+ * <script type="text/javascript">
927+ * var data = "<%=Encode.forJavaScript(data)%> ";
928+ * </script>
929929 * </pre>
930930 *
931- * <h5>Encoding Description</h5>
932931 * <table cellspacing="1" cellpadding="1" border="0">
932+ * <caption><b>Encoding Description</b></caption>
933933 * <thead>
934934 * <tr bgcolor="#ccf">
935935 * <th align="left" colspan="2">Input Character</th>
@@ -972,7 +972,7 @@ public static void forJava(Writer out, String input)
972972 * "\&quot;".)</td>
973973 * </tr>
974974 * <tr>
975- * <td>U+0026</td><td><code>&</code></td>
975+ * <td>U+0026</td><td><code>& </code></td>
976976 * <td><code>\x26</code></td>
977977 * <td>Ampersand character</td>
978978 * </tr>
@@ -988,7 +988,7 @@ public static void forJava(Writer out, String input)
988988 * <td>U+002F</td><td><code>/</code></td>
989989 * <td><code>\/</code></td>
990990 * <td>This encoding is used to avoid an input sequence
991- * "</" from prematurely terminating a </script>
991+ * "</" from prematurely terminating a </script>
992992 * block.</td>
993993 * </tr>
994994 * <tr>
@@ -1041,9 +1041,9 @@ public static void forJavaScript(Writer out, String input)
10411041 * recommend that you use {@link #forJavaScript(String)} over this
10421042 * method.</strong></p>
10431043 *
1044- * <h5 >Example JSP Usage:</h5 >
1044+ * <b >Example JSP Usage:</b >
10451045 * <pre>
1046- * <button onclick="alert('<%=Encode.forJavaScriptAttribute(data)%> ');">
1046+ * <button onclick="alert('<%=Encode.forJavaScriptAttribute(data)%> ');">
10471047 * </pre>
10481048 *
10491049 * @param input the input string to encode
@@ -1084,11 +1084,11 @@ public static void forJavaScriptAttribute(Writer out, String input)
10841084 * recommend that you use {@link #forJavaScript(String)} over this
10851085 * method.</strong></p>
10861086 *
1087- * <h5 >Example JSP Usage:</h5 >
1087+ * <b >Example JSP Usage:</b >
10881088 * <pre>
1089- * <script type="text/javascript">
1090- * var data = "<%=Encode.forJavaScriptBlock(data)%> ";
1091- * </script>
1089+ * <script type="text/javascript">
1090+ * var data = "<%=Encode.forJavaScriptBlock(data)%> ";
1091+ * </script>
10921092 * </pre>
10931093 *
10941094 * @param input the input string to encode
@@ -1129,19 +1129,19 @@ public static void forJavaScriptBlock(Writer out, String input)
11291129 * recommend that you use {@link #forJavaScript(String)} over this
11301130 * method.</strong></p>
11311131 *
1132- * <h5 >Example JSP Usage:</h5 >
1132+ * <b >Example JSP Usage:</b >
11331133 * This example is serving up JavaScript source directly:
11341134 * <pre>
1135- * <%@page contentType="text/javascript; charset=UTF-8"%>
1136- * var data = "<%=Encode.forJavaScriptSource(data)%> ";
1135+ * <%@page contentType="text/javascript; charset=UTF-8"%>
1136+ * var data = "<%=Encode.forJavaScriptSource(data)%> ";
11371137 * </pre>
11381138 *
11391139 * This example is serving up JSON data (users of this use-case
11401140 * are encouraged to read up on "JSON Hijacking"):
11411141 * <pre>
1142- * <%@page contentType="application/json; charset=UTF-8"%>
1143- * <% myapp.jsonHijackingPreventionMeasure(); %>
1144- * {"data":"<%=Encode.forJavaScriptSource(data)%> "}
1142+ * <%@page contentType="application/json; charset=UTF-8"%>
1143+ * <% myapp.jsonHijackingPreventionMeasure(); %>
1144+ * {"data":"<%=Encode.forJavaScriptSource(data)%> "}
11451145 * </pre>
11461146 *
11471147 * @param input the input string to encode
0 commit comments