GT-2698 code review

This commit is contained in:
dev747368 2019-04-16 18:50:05 -04:00
parent d7410690ff
commit 18bb622081
5 changed files with 34 additions and 16 deletions

View File

@ -48,9 +48,16 @@ public class HorizontalRuleAction extends DockingAction {
// the description is meant to be used for the tooltip and is larger
String padding = "     ";
setDescription("<HTML><CENTER><B>" + padding + HTMLUtilities.escapeHTML(topName) + padding +
"<B><HR><B>" + padding + HTMLUtilities.escapeHTML(bottomName) + padding +
"</B></CENTER>");
setDescription("<HTML><CENTER><B>" + padding +
fixupFirstAmp(HTMLUtilities.escapeHTML(topName) + padding + "<B><HR><B>" + padding +
HTMLUtilities.escapeHTML(bottomName)) +
padding + "</B></CENTER>");
}
private String fixupFirstAmp(String text) {
// add an extra & to replace the one that the MenuData will eat
int index = text.indexOf('&');
return index < 0 ? text : text.substring(0, index) + "&" + text.substring(index);
}
@Override

View File

@ -26,7 +26,7 @@ import javax.swing.*;
import org.junit.Assert;
import org.junit.Test;
import docking.widgets.label.GDHtmlLabel;
import docking.widgets.label.GHtmlLabel;
import ghidra.app.util.html.diff.*;
public class DataTypeDifferTest {
@ -490,24 +490,19 @@ public class DataTypeDifferTest {
JPanel panel = new JPanel(new BorderLayout());
JPanel rightPanel = new JPanel(new BorderLayout());
StringBuffer buffy1 = new StringBuffer(htmlLeft);
JLabel rightLabel = new GDHtmlLabel();
JLabel rightLabel = new GHtmlLabel(htmlLeft);
rightLabel.setOpaque(true);
rightLabel.setBackground(Color.WHITE);
rightLabel.setVerticalAlignment(SwingConstants.TOP);
rightPanel.add(rightLabel);
JPanel leftPanel = new JPanel(new BorderLayout());
StringBuffer buffy2 = new StringBuffer(htmlRight);
JLabel leftLabel = new GDHtmlLabel();
JLabel leftLabel = new GHtmlLabel(htmlRight);
leftLabel.setOpaque(true);
leftLabel.setBackground(Color.WHITE);
leftLabel.setVerticalAlignment(SwingConstants.TOP);
leftPanel.add(leftLabel);
rightLabel.setText(buffy1.toString());
leftLabel.setText(buffy2.toString());
JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel),
new JScrollPane(rightPanel));
pane.setResizeWeight(.5);

View File

@ -601,9 +601,12 @@ public class HTMLUtilities {
/**
* Escapes any HTML special characters in the specified text.
* <p>
* Does not otherwise modify the input text or wrap lines.
* 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.
* <p>
* See also {@link StringEscapeUtils#escapeHtml3(String)} if you need quote-safe html encoding.
* <p>
* See also {@link StringEscapeUtils#escapeHtml3(String)}.
*
* @param text plain-text that might have some characters that should NOT be interpreted as HTML
* @return string with any html characters replaced with equivalents

View File

@ -173,4 +173,17 @@ public class HTMLUtilitiesTest {
String htmlStr = HTMLUtilities.convertLinkPlaceholdersToHyperlinks(placeholderStr);
assertEquals("<A HREF=\"test\">Stuff inside <b>link</b> tag</A>", htmlStr);
}
@Test
public void testEscapeHTML() {
assertEquals("abc", HTMLUtilities.escapeHTML("abc"));
assertEquals("&#x2222;", HTMLUtilities.escapeHTML("\u2222"));
// unicode char above 0xffff encoded with 2 utf-16 characters
assertEquals("&#x1F344;", HTMLUtilities.escapeHTML("\uD83C\uDF44"));
assertEquals("&lt;abc&gt;", HTMLUtilities.escapeHTML("<abc>"));
assertEquals("a&amp;b", HTMLUtilities.escapeHTML("a&b"));
}
}

View File

@ -30,7 +30,7 @@ import docking.ComponentProvider;
import docking.action.DockingActionIf;
import docking.help.Help;
import docking.help.HelpService;
import docking.widgets.label.GDHtmlLabel;
import docking.widgets.label.GHtmlLabel;
import docking.widgets.table.*;
import docking.widgets.table.threaded.*;
import ghidra.framework.main.FrontEndPlugin;
@ -222,8 +222,8 @@ public class ProjectDataTablePanel extends JPanel {
}
}
private JLabel capacityExceededText =
new GDHtmlLabel("<HTML><CENTER><I>Table view disabled for very large projects, or<BR>" +
private GHtmlLabel capacityExceededText =
new GHtmlLabel("<HTML><CENTER><I>Table view disabled for very large projects, or<BR>" +
"if an older project/repository filesystem is in use.<BR>" +
"View will remain disabled until project is closed.</I></CENTER></HTML>");