This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-bcel.git
The following commit(s) were added to refs/heads/master by this push:
new f07a5479 Document Class2HTML escaping helpers
f07a5479 is described below
commit f07a5479bac26c770624d0c6752be712e36ae61f
Author: Gary Gregory <[email protected]>
AuthorDate: Fri Nov 20 12:06:04 2026 -0500
Document Class2HTML escaping helpers
Describe HTML character escaping and newline rendering in toHTML().
Clarify UTF-8 filename encoding in toHTMLRef(), and document parameters,
return values, null handling, and cross-references for both helpers.
---
src/main/java/org/apache/bcel/util/Class2HTML.java | 26 ++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/bcel/util/Class2HTML.java
b/src/main/java/org/apache/bcel/util/Class2HTML.java
index 5b242395..0cd5ac70 100644
--- a/src/main/java/org/apache/bcel/util/Class2HTML.java
+++ b/src/main/java/org/apache/bcel/util/Class2HTML.java
@@ -180,6 +180,19 @@ public class Class2HTML implements Constants {
return "<A HREF=\"" + toHTMLRef(baseType) + ".html\" TARGET=_top>" +
toHTML(shortType) + "</A>";
}
+ /**
+ * Escapes text for inclusion in an HTML report.
+ *
+ * <p>
+ * Replaces ampersands, angle brackets, double quotes, and single quotes
with HTML entities. Line feed and carriage return characters become the literal
+ * sequences {@code \n} and {@code \r}, respectively. All other characters
are copied unchanged.
+ * </p>
+ *
+ * @param str the non-null text to escape.
+ * @return the HTML-escaped text.
+ * @throws NullPointerException if {@code str} is null.
+ * @see #toHTMLRef(String)
+ */
static String toHTML(final String str) {
final StringBuilder buf = new StringBuilder();
for (int i = 0; i < str.length(); i++) {
@@ -214,8 +227,17 @@ public class Class2HTML implements Constants {
}
/**
- * Encodes a class or type name as a UTF-8 file name in an HTML link.
Spaces use percent escapes rather than the form encoding's plus signs, and HTML
- * metacharacters are percent-encoded as well. Any ':' is replaced so a
name cannot introduce a URL scheme such as "javascript:".
+ * Encodes a class or type name as a file-name component in an HTML report
link.
+ *
+ * <p>
+ * Replaces colons with underscores, then percent-encodes the name using
UTF-8. Spaces become {@code %20}, and HTML metacharacters are percent-encoded.
+ * The caller appends report suffixes and URL fragments to the encoded
name.
+ * </p>
+ *
+ * @param str the non-null class or type name to encode.
+ * @return the encoded file-name component.
+ * @throws NullPointerException if {@code str} is null.
+ * @see #toHTML(String)
*/
static String toHTMLRef(final String str) {
try {