Skip to content

Ghidra is a software reverse engineering (SRE) framework

GT-3147 - Fixed html line wrapping regression

dragonmacherdcc6a763d26c
diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java
index 98d79a0e00..9bd6dac93e 100644
--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java
+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java
@@ -25,7 +25,7 @@ import javax.swing.JLabel;
import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View;
-import org.apache.commons.lang3.StringEscapeUtils;
+import org.apache.commons.lang3.StringUtils;
import generic.text.TextLayoutGraphics;
import ghidra.util.html.HtmlLineSplitter;
@@ -143,6 +143,7 @@ public class HTMLUtilities {
public static String HTML_SPACE = " ";
public static String HTML_NEW_LINE = BR;
+ private static String HTML_TAB = StringUtils.repeat(HTML_SPACE, 4);
public static final String MAROON = "#990000";
public static final String GREEN = "#009900";
@@ -522,7 +523,7 @@ public class HTMLUtilities {
}
/**
- * @see {@link #friendlyEncodeHTML(String)}
+ * See {@link #friendlyEncodeHTML(String)}
*
* @param text string to be encoded
* @param skipLeadingWhitespace true signals to ignore any leading whitespace characters.
@@ -603,9 +604,11 @@ public class HTMLUtilities {
* <p>
* Does not otherwise modify the input text or wrap lines.
* <p>
- * Calling this twice will result in text being double-escaped, which will not display correctly.
+ * Calling this twice will result in text being double-escaped, which will not display
+ * correctly.
* <p>
- * See also {@link StringEscapeUtils#escapeHtml3(String)} if you need quote-safe html encoding.
+ * See also <code>StringEscapeUtils#escapeHtml3(String)</code> if you need quote-safe html
+ * encoding.
* <p>
*
* @param text plain-text that might have some characters that should NOT be interpreted as HTML
@@ -625,6 +628,20 @@ public class HTMLUtilities {
case '>':
buffer.append("&gt;");
break;
+ case '\n':
+ // Note: it is not clear why we are escaping characters less than space. We
+ // have client code calling this method that relies on newlines and tabs
+ // getting displayed. This method needs to document how it works with
+ // characters that get escaped. Further, if this method should escape
+ // all characters as is done below, then we have to look at every use
+ // of this method to ensure that if it needs whitespace fixup, that
+ // it calls friendlyEncodeHTML().
+ buffer.append(BR);
+ break;
+ case '\t':
+ // (see the above note)
+ buffer.append(HTML_TAB);
+ break;
default:
if (cp < ' ' || cp >= 0x7F) {
buffer.append("&#x");