Skip to content

Commit 0e2d54f

Browse files
authored
fixed a small oob bug with extracting code (#696)
* happens in rare conditions when the message is ````` or similar, i.e. more than three backticks
1 parent 94ab671 commit 0e2d54f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,15 @@ public static Optional<CodeFence> extractCode(String fullMessage) {
180180
return Optional.empty();
181181
}
182182

183-
int codeFenceEnd = fullMessage.indexOf(CODE_FENCE_SYMBOL, codeFenceStart + 1);
183+
int languageStart = codeFenceStart + CODE_FENCE_SYMBOL.length();
184+
int codeFenceEnd = fullMessage.indexOf(CODE_FENCE_SYMBOL, languageStart);
184185
if (codeFenceEnd == -1) {
185186
return Optional.empty();
186187
}
187188

188189
// Language is between ``` and newline, no spaces allowed, like ```java
189190
// Look for the next newline and then assert no space between
190191
String language = null;
191-
int languageStart = codeFenceStart + CODE_FENCE_SYMBOL.length();
192192
int languageEnd = fullMessage.indexOf('\n', codeFenceStart);
193193
if (languageEnd != -1) {
194194
String languageCandidate = fullMessage.substring(languageStart, languageEnd);

0 commit comments

Comments
 (0)