Fix bug report layout issue

Fixes an issue where some parts of the bug report would be formatted as HTML instead of plain text, e.g. in a stack trace '<init>' was previously recognized as an HTML tag.
This commit is contained in:
SiboVG 2022-02-10 20:12:42 +01:00
parent 1a68225cf3
commit b94440cc10

View File

@ -18,7 +18,6 @@ import javax.swing.JEditorPane;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane; import javax.swing.JTextPane;
import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.JoglVersion;
@ -180,7 +179,8 @@ public class BugReportDialog extends JDialog {
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw); e.printStackTrace(pw);
sb.append(sw.getBuffer()); String stackTrace = unformatHTML(String.valueOf(sw.getBuffer()));
sb.append(stackTrace);
sb.append('\n'); sb.append('\n');
@ -207,12 +207,13 @@ public class BugReportDialog extends JDialog {
} }
private static void addSystemInformation(StringBuilder sb) { private static void addSystemInformation(StringBuilder sb) {
sb.append("OpenRocket version: " + BuildProperties.getVersion() + "\n"); StringBuilder sbTemp = new StringBuilder();
sb.append("OpenRocket source: " + BuildProperties.getBuildSource() + "\n"); sbTemp.append("OpenRocket version: " + BuildProperties.getVersion() + "\n");
sb.append("OpenRocket location: " + JarUtil.getCurrentJarFile() + "\n"); sbTemp.append("OpenRocket source: " + BuildProperties.getBuildSource() + "\n");
sb.append("JOGL version: " + JoglVersion.getInstance().getImplementationVersion() + "\n"); sbTemp.append("OpenRocket location: " + JarUtil.getCurrentJarFile() + "\n");
sb.append("Current default locale: " + Locale.getDefault() + "\n"); sbTemp.append("JOGL version: " + JoglVersion.getInstance().getImplementationVersion() + "\n");
sb.append("System properties:\n"); sbTemp.append("Current default locale: " + Locale.getDefault() + "\n");
sbTemp.append("System properties:\n");
// Sort the keys // Sort the keys
SortedSet<String> keys = new TreeSet<String>(); SortedSet<String> keys = new TreeSet<String>();
@ -222,24 +223,31 @@ public class BugReportDialog extends JDialog {
for (String key : keys) { for (String key : keys) {
String value = System.getProperty(key); String value = System.getProperty(key);
sb.append(" " + key + "="); sbTemp.append(" " + key + "=");
if (key.equals("line.separator")) { if (key.equals("line.separator")) {
for (char c : value.toCharArray()) { for (char c : value.toCharArray()) {
sb.append(String.format("\\u%04x", (int) c)); sbTemp.append(String.format("\\u%04x", (int) c));
} }
} else { } else {
sb.append(value); sbTemp.append(value);
} }
sb.append('\n'); sbTemp.append('\n');
} }
String message = unformatHTML(sbTemp.toString());
sb.append(message);
} }
private static void addErrorLog(StringBuilder sb) { private static void addErrorLog(StringBuilder sb) {
StringBuilder sbTemp = new StringBuilder();
LogLevelBufferLogger buffer = LoggingSystemSetup.getBufferLogger(); LogLevelBufferLogger buffer = LoggingSystemSetup.getBufferLogger();
List<LogLine> logs = buffer.getLogs(); List<LogLine> logs = buffer.getLogs();
for (LogLine l : logs) { for (LogLine l : logs) {
sb.append(l.toString()).append('\n'); sbTemp.append(l.toString()).append('\n');
} }
String message = unformatHTML(sbTemp.toString());
sb.append(message);
} }
/** /**
@ -253,4 +261,13 @@ public class BugReportDialog extends JDialog {
return text.replaceAll("\n(.*?)(?=(\n|$))", "<p style=\"margin-top: 0\">$1</p>"); return text.replaceAll("\n(.*?)(?=(\n|$))", "<p style=\"margin-top: 0\">$1</p>");
} }
/**
* Makes text HTML unformatted by replacing '<' and '>' by the HTML character equivalent
* @param text text to be replaced
* @return HTML unformatted text
*/
private static String unformatHTML(String text) {
return text.replace("<", "&lt;").replace(">", "&gt;");
}
} }