Skip to content

Commit

Permalink
Merge pull request #819 from KyoriPowered/fix/non-terminating-quote
Browse files Browse the repository at this point in the history
minimessage: Parsing corner cases with quotes
  • Loading branch information
zml2008 committed Nov 7, 2022
2 parents 0e52a93 + 8b71690 commit d82d5ac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Expand Up @@ -246,8 +246,11 @@ public static void parseString(final String message, final MatchedTokenConsumer<
break;
case '\'':
case '"':
state = FirstPassState.STRING;
currentStringChar = (char) codePoint;
// Look ahead if the quote being opened is ever closed
if (message.indexOf(codePoint, i + 1) != -1) {
state = FirstPassState.STRING;
}
break;
}
break;
Expand All @@ -257,6 +260,14 @@ public static void parseString(final String message, final MatchedTokenConsumer<
}
break;
}

if (i == (length - 1) && state == FirstPassState.TAG) {
// We've reached the end of the input with an open `<`, but it was never matched to a closing `>`.
// Anything which was inside of quotes needs to be parsed again, as it may contain additional tags.
// Rewind back to directly after the `<`, but in the NORMAL state, instead of TAG.
i = marker;
state = FirstPassState.NORMAL;
}
}

// anything left over is plain text
Expand Down
Expand Up @@ -280,6 +280,26 @@ void testQuoteEscapingInArguments() {
this.assertParsedEquals(expected3, input3);
}

@Test
void testNonTerminatingQuote() {
final Component expected = empty().append(text("Remember the<3\"").color(RED)).append(text(" bug"));
final Component expected1 = empty().append(text("Remember the<3'").color(RED)).append(text(" bug"));
final Component expected2 = empty().append(text("Remember the<h:\"").color(RED)).append(text(" bug"));
final Component expected3 = empty().append(text("Remember the<h:\"").color(RED)).append(text(" \"bug"));
// This one is an actually valid use of quotes
final Component expected4 = empty().append(text("Remember the<h:\"</red> \">bug").color(RED));
final String input = "<red>Remember the<3\"</red> bug";
final String input1 = "<red>Remember the<3'</red> bug";
final String input2 = "<red>Remember the<h:\"</red> bug";
final String input3 = "<red>Remember the<h:\"</red> \"bug";
final String input4 = "<red>Remember the<h:\"</red> \">bug";
this.assertParsedEquals(expected, input);
this.assertParsedEquals(expected1, input1);
this.assertParsedEquals(expected2, input2);
this.assertParsedEquals(expected3, input3);
this.assertParsedEquals(expected4, input4);
}

// GH-68, GH-93
@Test
void testAngleBracketsShit() {
Expand Down

0 comments on commit d82d5ac

Please sign in to comment.