From 3e0b4eb7d3c58adf49c421c10f78b6fb356daded Mon Sep 17 00:00:00 2001 From: Emilia Kond Date: Tue, 19 Dec 2023 08:00:30 +0200 Subject: [PATCH] minimessage: Fix exception with single quote as tag part The parser tries to un-quote tag parts surrounded by quotes, it does so by checking if the first character of the tag part is a quote and the last character is as well. However, things break if that first and last character are actually the same character! A StringIndexOutOfBoundsException is thrown later on. This patch makes it so tag parts consisting of a single quote aren't tried to be un-quoted, they stay as is Fixes https://github.com/KyoriPowered/adventure/issues/1011 --- .../text/minimessage/internal/parser/node/TagPart.java | 5 +++++ .../text/minimessage/MiniMessageParserTest.java | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/internal/parser/node/TagPart.java b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/internal/parser/node/TagPart.java index 3e21a4b02..09457e75a 100644 --- a/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/internal/parser/node/TagPart.java +++ b/text-minimessage/src/main/java/net/kyori/adventure/text/minimessage/internal/parser/node/TagPart.java @@ -106,6 +106,11 @@ public TagPart( endIndex--; } + if (startIndex > endIndex) { + // We were given only a single quote that doesn't terminate, we can't unescape it + return text.substring(start, end); + } + return TokenParser.unescape(text, startIndex, endIndex, i -> i == firstChar || i == TokenParser.ESCAPE); } diff --git a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java index f6606bb56..84b1fa027 100644 --- a/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java +++ b/text-minimessage/src/test/java/net/kyori/adventure/text/minimessage/MiniMessageParserTest.java @@ -544,4 +544,13 @@ public boolean has(final @NotNull String name) { this.assertParsedEquals(expected, input, alwaysMatchingResolver); } + + // https://github.com/KyoriPowered/adventure/issues/1011 + @Test + void testNonTerminatingQuoteArgument() { + final String input = ""; + final Component expected = Component.text(input); + + this.assertParsedEquals(expected, input); + } }