Ghidra is a software reverse engineering (SRE) framework
GT-3147 - review fixes
dragonmacher42f3de2e69a1
diff --git a/Ghidra/Features/Base/src/main/help/help/topics/GhidraScriptMgrPlugin/ScriptDevelopment.htm b/Ghidra/Features/Base/src/main/help/help/topics/GhidraScriptMgrPlugin/ScriptDevelopment.htmindex e1929224ed..a4aa8f82ee 100644--- a/Ghidra/Features/Base/src/main/help/help/topics/GhidraScriptMgrPlugin/ScriptDevelopment.htm+++ b/Ghidra/Features/Base/src/main/help/help/topics/GhidraScriptMgrPlugin/ScriptDevelopment.htm@@ -52,8 +52,7 @@<BLOCKQUOTE><P>The scripting framework supports special meta-data comments. This comment is treated- specially by the script manager. A meta-data comment may contain HTML characters (such as- <pre> and <code>).</P>+ specially by the script manager.</P><OL><LI>Each line of meta-data should start with the scripting language comment character. Fordiff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptInfo.java b/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptInfo.javaindex 0860d95dfd..6447e1984d 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptInfo.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/script/ScriptInfo.java@@ -15,8 +15,7 @@*/package ghidra.app.script;-import static ghidra.util.HTMLUtilities.HTML_NEW_LINE;-import static ghidra.util.HTMLUtilities.HTML_SPACE;+import static ghidra.util.HTMLUtilities.*;import java.io.*;import java.util.List;@@ -30,7 +29,6 @@ import org.apache.commons.lang3.StringUtils;import docking.actions.KeyBindingUtils;import generic.jar.ResourceFile;-import ghidra.util.HTMLUtilities;import ghidra.util.Msg;import resources.ResourceManager;@@ -431,41 +429,39 @@ public class ScriptInfo {}/**- * Returns a string designed to be used as a tool tip- * for describing this script.+ * Returns a string designed to be used as a tool tip for describing this script* @return a string designed to be used as a tool tip*/public String getToolTipText() {- String htmlDescription = (description == null) ? "No Description"- : HTMLUtilities.escapeHTML(description).replaceAll("\n",- HTML_NEW_LINE + HTML_SPACE);- String htmlAuthor = HTMLUtilities.bold("Author:") + HTML_SPACE +- HTMLUtilities.escapeHTML(toToolTip(author));- String htmlCategory = HTMLUtilities.bold("Category:") + HTML_SPACE +- HTMLUtilities.escapeHTML(toToolTip(StringUtils.join(category, DELIMITTER)));-- String htmlKeyBinding =- HTMLUtilities.bold("Key Binding:") + HTML_SPACE + getKeybindingToolTip();- String htmlMenuPath = HTMLUtilities.bold("Menu Path:") + HTML_SPACE +- HTMLUtilities.escapeHTML(toToolTip(StringUtils.join(menupath, DELIMITTER)));+ String htmlDescription = "No Description";+ if (description != null) {+ htmlDescription = escapeHTML(description);+ htmlDescription = htmlDescription.replaceAll("\n", HTML_NEW_LINE + HTML_SPACE);+ }++ String space = HTML_SPACE;+ String htmlAuthor = bold("Author:") + space + escapeHTML(toString(author));+ String htmlCategory = bold("Category:") + space + escapeHTML(toString(category));++ String htmlKeyBinding = bold("Key Binding:") + space + getKeybindingToolTip();+ String htmlMenuPath = bold("Menu Path:") + space + escapeHTML(toString(menupath));StringBuilder buffer = new StringBuilder();- buffer.append("<h3>").append(HTML_SPACE).append(HTMLUtilities.escapeHTML(getName())).append(- "</h3>");+ buffer.append("<h3>").append(space).append(escapeHTML(getName())).append("</h3>");buffer.append(HTML_NEW_LINE);- buffer.append(HTML_SPACE).append(htmlDescription);+ buffer.append(space).append(htmlDescription);buffer.append(HTML_NEW_LINE);buffer.append(HTML_NEW_LINE);- buffer.append(HTML_SPACE).append(htmlAuthor);+ buffer.append(space).append(htmlAuthor);buffer.append(HTML_NEW_LINE);- buffer.append(HTML_SPACE).append(htmlCategory);+ buffer.append(space).append(htmlCategory);buffer.append(HTML_NEW_LINE);- buffer.append(HTML_SPACE).append(htmlKeyBinding);+ buffer.append(space).append(htmlKeyBinding);buffer.append(HTML_NEW_LINE);- buffer.append(HTML_SPACE).append(htmlMenuPath);+ buffer.append(space).append(htmlMenuPath);buffer.append(HTML_NEW_LINE);buffer.append(HTML_NEW_LINE);- return HTMLUtilities.wrapAsHTML(buffer.toString());+ return wrapAsHTML(buffer.toString());}private String getKeybindingToolTip() {@@ -482,11 +478,13 @@ public class ScriptInfo {return KeyBindingUtils.parseKeyStroke(keyStroke);}- private String toToolTip(String string) {- if (string == null || string.length() == 0) {- return "";- }- return string;+ private String toString(String string) {+ return StringUtils.defaultString(string);+ }++ private String toString(String[] path) {+ String joined = StringUtils.join(path, DELIMITTER);+ return StringUtils.defaultString(joined);}public boolean hasErrors() {diff --git a/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java b/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.javaindex 9bd6dac93e..77f6dfb9a6 100644--- a/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java+++ b/Ghidra/Framework/Generic/src/main/java/ghidra/util/HTMLUtilities.java@@ -25,8 +25,6 @@ import javax.swing.JLabel;import javax.swing.plaf.basic.BasicHTML;import javax.swing.text.View;-import org.apache.commons.lang3.StringUtils;-import generic.text.TextLayoutGraphics;import ghidra.util.html.HtmlLineSplitter;import utilities.util.reflection.ReflectionUtilities;@@ -143,7 +141,6 @@ 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";@@ -604,11 +601,9 @@ 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 <code>StringEscapeUtils#escapeHtml3(String)</code> 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@@ -628,22 +623,8 @@ public class HTMLUtilities {case '>':buffer.append(">");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) {+ if (charNeedsHTMLEscaping(cp)) {buffer.append("&#x");buffer.append(Integer.toString(cp, 16).toUpperCase());buffer.append(";");@@ -658,6 +639,21 @@ public class HTMLUtilities {return buffer.toString();}+ /**+ * Tests a unicode code point (i.e., 32 bit character) to see if it needs to be escaped before+ * being added to a HTML document because it is non-printable or a non-standard control+ * character+ *+ * @param codePoint character to test+ * @return boolean true if character should be escaped+ */+ public static boolean charNeedsHTMLEscaping(int codePoint) {+ if (codePoint == '\n' || codePoint == '\t' || (' ' <= codePoint && codePoint < 0x7F)) {+ return false;+ }+ return true;+ }+/*** A convenience method to split the given HTML into lines, based on the given length, and* then to {@link #friendlyEncodeHTML(String)} the text.