Escape crash message and stacktrace placeholders

This prevents warnings about '<init>' "tags" found in call stacks, or because of unescaped messages.
This commit is contained in:
JeremyStar™ 2024-08-17 21:37:45 +02:00
parent db52346168
commit 72b40613b8
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 13 additions and 4 deletions

View file

@ -99,6 +99,9 @@ public final class Stacktrace implements Placeholder {
if (throwable instanceof InvocationTargetException invocationTargetException) if (throwable instanceof InvocationTargetException invocationTargetException)
getFullStackTrace(invocationTargetException.getTargetException(), stacktrace); getFullStackTrace(invocationTargetException.getTargetException(), stacktrace);
return stacktrace.toString(); // Return stack trace // Return stack trace
return stacktrace
.toString()
.replace("<", "\\<");
} }
} }

View file

@ -66,6 +66,6 @@ public final class StacktraceAll implements Placeholder {
.append(Miscellaneous.stringifyStackTrace(stacktraces.get(thread), false)); .append(Miscellaneous.stringifyStackTrace(stacktraces.get(thread), false));
} }
return text.replace("%stacktrace_all%", output.toString()); return text.replace("%stacktrace_all%", output.toString().replace("<", "\\<"));
} }
} }

View file

@ -117,12 +117,18 @@ Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party su
* @since v1-alpha0 * @since v1-alpha0
*/ */
public static synchronized void handleCrash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @Nullable Throwable throwable, boolean throwableHandled) { public static synchronized void handleCrash(@NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @Nullable Throwable throwable, boolean throwableHandled) {
Engine.getInstance().setState(EngineState.CRASHED); Engine.getInstance().setState(EngineState.CRASHED); // Update engine state
// Prevent throwable handled warning if set to true but no throwable has been supplied
if (throwable == null) if (throwable == null)
throwableHandled = false; throwableHandled = false;
// This is so simple we don't need the PlaceholderEngine to do it for us // Escape message
message = message
.replace("\\", "\\\\")
.replace("<", "\\<");
// Replace %content% and %handled%
String base = crashTemplate String base = crashTemplate
.replace("%content%", processCrashContent()) .replace("%content%", processCrashContent())
.replace("%handled%", throwableHandled ? "!!! This throwable is declared as handled and has been passed down the execution chain !!!" : ""); .replace("%handled%", throwableHandled ? "!!! This throwable is declared as handled and has been passed down the execution chain !!!" : "");