Skip to content

Commit

Permalink
Protect against IndexOutOfBounds from highlighterIterator
Browse files Browse the repository at this point in the history
Fixes #1865
  • Loading branch information
KronicDeth committed Jan 7, 2021
1 parent cac8ff5 commit 94fca03
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/org/elixir_lang/QuoteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,22 @@ public boolean hasNonClosedLiteral(Editor editor, HighlighterIterator highlighte
*/
@Override
public boolean isClosingQuote(HighlighterIterator highlighterIterator, int offset) {
boolean isClosingQuote = false;
IElementType tokenType;

if (CLOSING_QUOTES.contains(highlighterIterator.getTokenType())) {
try {
tokenType = highlighterIterator.getTokenType();
} catch (IndexOutOfBoundsException e) {
tokenType = null;
}

boolean isClosingQuote;

if (CLOSING_QUOTES.contains(tokenType)) {
int start = highlighterIterator.getStart();
int end = highlighterIterator.getEnd();
isClosingQuote = end - start >= 1 && offset == end - 1;
} else {
isClosingQuote = false;
}

return isClosingQuote;
Expand All @@ -143,11 +153,21 @@ public boolean isInsideLiteral(HighlighterIterator highlighterIterator) {

@Override
public boolean isOpeningQuote(HighlighterIterator highlighterIterator, int offset) {
boolean isOpeningQuote = false;
IElementType tokenType;

try {
tokenType = highlighterIterator.getTokenType();
} catch (IndexOutOfBoundsException e) {
tokenType = null;
}

boolean isOpeningQuote;

if (OPENING_QUOTES.contains(highlighterIterator.getTokenType())){
if (OPENING_QUOTES.contains(tokenType)){
int start = highlighterIterator.getStart();
isOpeningQuote = offset == start;
} else {
isOpeningQuote = false;
}

return isOpeningQuote;
Expand Down

0 comments on commit 94fca03

Please sign in to comment.