diff --git a/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java b/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java index 5ad2d52..d3335cd 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java +++ b/base/src/main/java/de/staropensource/sosengine/base/classes/ShortcodeParserSkeleton.java @@ -20,6 +20,7 @@ package de.staropensource.sosengine.base.classes; import de.staropensource.sosengine.base.EngineConfiguration; +import de.staropensource.sosengine.base.exceptions.ParserException; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; import de.staropensource.sosengine.base.types.logging.LogIssuer; @@ -76,28 +77,51 @@ public abstract class ShortcodeParserSkeleton { * Constructs this class. * * @param string string to parse + * @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text + * @throws ParserException when parsing failed * @since v1-alpha1 */ - public ShortcodeParserSkeleton(@NotNull String string) { - components = parse(string); + public ShortcodeParserSkeleton(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException { + components = parse(string, ignoreInvalidEscapes); } /** * Parses an input string and spits out all of it's components. * - * @param string string to parse + * @param string string to parse + * @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text * @return list of components + * @throws ParserException when parsing failed * @see EngineConfiguration#errorShortcodeConverter * @since v1-alpha1 */ @NotNull - protected LinkedList<@NotNull String> parse(@NotNull String string) { + protected LinkedList<@NotNull String> parse(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException { LinkedList components = new LinkedList<>(); // List of components - boolean tagActive = false; // Indicates that a tag is being parsed - String part = ""; // Current part. May be a tag, may be regular text + boolean tagActive = false; // Indicates that a tag is being parsed + boolean escape = false; // Indicates whether the last character was a \ character + String part = ""; // Temporary string. May be a tag, may be regular text // Iterate through every character for (char character : string.toCharArray()) { + // Escaping + if (escape) { + if (character == '\\' || character == '<') + part += character; + else if (!(character == 'r' || character == 'n')) + if (ignoreInvalidEscapes) + part += "\\" + character; + else + throw new ParserException("Invalid escape \\" + character); + + escape = false; + continue; + } + if (character == '\\') { + escape = true; + continue; + } + if (tagActive) { // A tag is being parsed if (character == '>') { diff --git a/base/src/main/java/de/staropensource/sosengine/base/exceptions/ParserException.java b/base/src/main/java/de/staropensource/sosengine/base/exceptions/ParserException.java index f17d4f3..7c4c91c 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/exceptions/ParserException.java +++ b/base/src/main/java/de/staropensource/sosengine/base/exceptions/ParserException.java @@ -26,7 +26,7 @@ import org.jetbrains.annotations.NotNull; * * @since v1-alpha2 */ -public class ParserException extends Exception { +public class ParserException extends RuntimeException { public ParserException(@NotNull String message) { super(message); } diff --git a/base/src/main/java/de/staropensource/sosengine/base/internal/placeholders/crashhandler/IssuerInfo.java b/base/src/main/java/de/staropensource/sosengine/base/internal/placeholders/crashhandler/IssuerInfo.java index 697c9e9..ae43bb6 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/internal/placeholders/crashhandler/IssuerInfo.java +++ b/base/src/main/java/de/staropensource/sosengine/base/internal/placeholders/crashhandler/IssuerInfo.java @@ -53,7 +53,7 @@ public final class IssuerInfo implements Placeholder { @NotNull @Override public String replace(@NotNull String text) { - String replacement = ""; + String replacement = "\\"; if (logIssuer.getAdditionalInformation() != null) replacement = logIssuer.getAdditionalInformation(); diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java b/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java index 623771b..8040473 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/CrashHandler.java @@ -75,14 +75,14 @@ public final class CrashHandler { sos!engine crash ------------------------ -Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you <3 +Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you \\<3 Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party subsystems are causing problems. - If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you <3 + If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you \\<3 %content% -Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you <3 +Dear user: The application or game you've tried to use seems to have made an oopsie. Please report this to the developer so they can fix it! Thank you \\<3 Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party subsystems are causing problems. - If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you <3 + If not, please report it at https://git.staropensource.de/StarOpenSource/Engine/issues. Thank you \\<3 ------------------------ sos!engine crash diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/ColoredLoggerImpl.java b/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/ColoredLoggerImpl.java index d12761d..a72a3c5 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/ColoredLoggerImpl.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/ColoredLoggerImpl.java @@ -66,7 +66,7 @@ public class ColoredLoggerImpl implements LoggerImpl { @Override public void print(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String format) { // Convert to Ansi - Ansi output = new AnsiShortcodeConverter(format).getAnsi(); + Ansi output = new AnsiShortcodeConverter(format, true).getAnsi(); // Print message if (level == LogLevel.ERROR || level == LogLevel.CRASH) diff --git a/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/PlainLoggerImpl.java b/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/PlainLoggerImpl.java index fedbfc9..d3cad51 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/PlainLoggerImpl.java +++ b/base/src/main/java/de/staropensource/sosengine/base/logging/implementation/PlainLoggerImpl.java @@ -62,7 +62,7 @@ public class PlainLoggerImpl implements LoggerImpl { /** {@inheritDoc} */ @Override public void print(@NotNull LogLevel level, @NotNull LogIssuer logIssuer, @NotNull String format) { - format = new EmptyShortcodeConverter(format).getClean(); + format = new EmptyShortcodeConverter(format, true).getClean(); if (level == LogLevel.ERROR || level == LogLevel.CRASH) if (EngineConfiguration.getInstance().isLoggerForceStandardOutput()) System.out.println(format); diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/converter/AnsiShortcodeConverter.java b/base/src/main/java/de/staropensource/sosengine/base/utility/converter/AnsiShortcodeConverter.java index 5080aa0..7ec8310 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/converter/AnsiShortcodeConverter.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/converter/AnsiShortcodeConverter.java @@ -20,6 +20,7 @@ package de.staropensource.sosengine.base.utility.converter; import de.staropensource.sosengine.base.classes.ShortcodeParserSkeleton; +import de.staropensource.sosengine.base.exceptions.ParserException; import org.fusesource.jansi.Ansi; import org.jetbrains.annotations.NotNull; @@ -35,10 +36,12 @@ public final class AnsiShortcodeConverter extends ShortcodeParserSkeleton { * Constructs this class. * * @param string string to convert + * @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text + * @throws ParserException when parsing failed * @since v1-alpha0 */ - public AnsiShortcodeConverter(@NotNull String string) { - super(string); + public AnsiShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException { + super(string, ignoreInvalidEscapes); } /** diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/converter/EmptyShortcodeConverter.java b/base/src/main/java/de/staropensource/sosengine/base/utility/converter/EmptyShortcodeConverter.java index ef70195..dd94e3e 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/converter/EmptyShortcodeConverter.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/converter/EmptyShortcodeConverter.java @@ -20,6 +20,7 @@ package de.staropensource.sosengine.base.utility.converter; import de.staropensource.sosengine.base.classes.ShortcodeParserSkeleton; +import de.staropensource.sosengine.base.exceptions.ParserException; import org.jetbrains.annotations.NotNull; /** @@ -34,10 +35,12 @@ public final class EmptyShortcodeConverter extends ShortcodeParserSkeleton { * Constructs this class. * * @param string string to convert + * @param ignoreInvalidEscapes will ignore invalid escapes and print treat them like regular text + * @throws ParserException when parsing failed * @since v1-alpha1 */ - public EmptyShortcodeConverter(@NotNull String string) { - super(string); + public EmptyShortcodeConverter(@NotNull String string, boolean ignoreInvalidEscapes) throws ParserException { + super(string, ignoreInvalidEscapes); } /**