Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minimessage: Parsing corner cases with quotes #819

Merged
merged 3 commits into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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