Skip to content

Commit

Permalink
minimessage: Fix exception with single quote as tag part
Browse files Browse the repository at this point in the history
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 #1011
  • Loading branch information
rymiel committed Dec 19, 2023
1 parent ee89b80 commit 3e0b4eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<hover:show_text_:\">";
final Component expected = Component.text(input);

this.assertParsedEquals(expected, input);
}
}

0 comments on commit 3e0b4eb

Please sign in to comment.