Skip to content

Commit

Permalink
Merge pull request #1866 from KronicDeth/1865
Browse files Browse the repository at this point in the history
Protect against IndexOutOfBounds from highlighterIterator
  • Loading branch information
KronicDeth committed Jan 7, 2021
2 parents 7c6a109 + bf41dd8 commit 76babb7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@
* Regenerate Parser for newer GrammarParser version.
* Port elixir-lang/elixir@1e4e05ef78b3105065f0a313bd0e1e78b2aa973e


### Bug Fixes
* [#1844](https://github.com/KronicDeth/intellij-elixir/pull/1844) - [@KronicDeth](https://github.com/KronicDeth)
* Fix deprecation warnings for IntelliJ IDEA 2020.2
Expand Down Expand Up @@ -342,8 +341,8 @@
* Heredoc with escapable newlines (#1843)
Heredocs allow the final newline to be escaped so you can write a heredoc in the code, but have no newlines in the string term at runtime.
* Fix terminators docs to show closing version and not opening version


* [#1866](https://github.com/KronicDeth/intellij-elixir/pull/1866) - [@KronicDeth](https://github.com/KronicDeth)
* Protect against `IndexOutOfBounds` from `highlighterIterator` in `QuoteHandler`.

## v11.8.1
### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions resources/META-INF/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ <h1>v11.9.0</h1>
<li>Convert <code>beam.assembly.ParserDefinition</code> to Kotlin</li>
</ul>
</li>
<li>
Protect against <code>IndexOutOfBounds</code> from <code>highlighterIterator</code> in
<code>QuoteHandler</code>.
</li>
</ul>
</li>
</ul>
Expand Down
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 76babb7

Please sign in to comment.