4040 * CDATAEncoder -- encoder for CDATA sections. CDATA sections are generally good for including large blocks of text that contain
4141 * characters that normally require encoding (ampersand, quotes, less-than, etc...). The CDATA context however still does not
4242 * allow invalid characters, and can be closed by the sequence "]]>". This encoder removes invalid XML characters, and encodes
43- * "]]>" (to "]]>]]<![CDATA[>"). The result is that the data integrity is maintained, but the code receiving the output will
44- * have to handle multiple CDATA events with character events between. As an alternate approach, the caller could pre-encode "]]>"
45- * to something of their choosing (e.g. data.replaceAll("\\]\\]>", "]] >")), then use this encoder to remove any invalid XML
46- * characters.
43+ * "]]>" (to "]]]]><![CDATA[>"). The result is that the data integrity is maintained, but the code receiving the output will
44+ * have to handle multiple CDATA events. As an alternate approach, the caller could pre-encode "]]>" to something of their
45+ * choosing (e.g. data.replaceAll("\\]\\]>", "]] >")), then use this encoder to remove any invalid XML characters.
4746 *
4847 * @author Jeff Ichnowski
4948 */
@@ -53,10 +52,10 @@ class CDATAEncoder extends Encoder {
5352 * The encoding of @{code "]]>"}.
5453 */
5554 private static final char [] CDATA_END_ENCODED
56- = "]]>]] <![CDATA[>" .toCharArray ();
55+ = "]]]]> <![CDATA[>" .toCharArray ();
5756
5857 /**
59- * Length of {@code "]]>]] <![CDATA[>"}.
58+ * Length of {@code "]]]]> <![CDATA[>"}.
6059 */
6160 private static final int CDATA_END_ENCODED_LENGTH = 15 ;
6261
@@ -69,8 +68,8 @@ class CDATAEncoder extends Encoder {
6968 protected int maxEncodedLength (int n ) {
7069 // "]" becomes "]" (1 -> 1)
7170 // "]]" becomes "]]" (2 -> 2)
72- // "]]>" becomes "]]>]] <![CDATA[>" (3 -> 15)
73- // "]]>]" becomes "]]>]] <![CDATA[>]" (3 -> 15 + 1 -> 1)
71+ // "]]>" becomes "]]]]> <![CDATA[>" (3 -> 15)
72+ // "]]>]" becomes "]]]]> <![CDATA[>]" (3 -> 15 + 1 -> 1)
7473 // ...
7574
7675 int worstCase = n / CDATA_END_LENGTH ;
0 commit comments