GT-3147 - Fixed html line wrapping regression

This commit is contained in:
dragonmacher 2019-09-12 12:11:20 -04:00
parent d9da0f0b66
commit dcc6a763d2

View file

@ -25,7 +25,7 @@ import javax.swing.JLabel;
import javax.swing.plaf.basic.BasicHTML; import javax.swing.plaf.basic.BasicHTML;
import javax.swing.text.View; import javax.swing.text.View;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils;
import generic.text.TextLayoutGraphics; import generic.text.TextLayoutGraphics;
import ghidra.util.html.HtmlLineSplitter; import ghidra.util.html.HtmlLineSplitter;
@ -143,6 +143,7 @@ public class HTMLUtilities {
public static String HTML_SPACE = " "; public static String HTML_SPACE = " ";
public static String HTML_NEW_LINE = BR; 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 MAROON = "#990000";
public static final String GREEN = "#009900"; 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 text string to be encoded
* @param skipLeadingWhitespace true signals to ignore any leading whitespace characters. * @param skipLeadingWhitespace true signals to ignore any leading whitespace characters.
@ -603,9 +604,11 @@ public class HTMLUtilities {
* <p> * <p>
* Does not otherwise modify the input text or wrap lines. * Does not otherwise modify the input text or wrap lines.
* <p> * <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> * <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> * <p>
* *
* @param text plain-text that might have some characters that should NOT be interpreted as HTML * @param text plain-text that might have some characters that should NOT be interpreted as HTML
@ -625,6 +628,20 @@ public class HTMLUtilities {
case '>': case '>':
buffer.append("&gt;"); buffer.append("&gt;");
break; 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: default:
if (cp < ' ' || cp >= 0x7F) { if (cp < ' ' || cp >= 0x7F) {
buffer.append("&#x"); buffer.append("&#x");