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

Protect against IndexOutOfBounds from highlighterIterator #1866

Merged
merged 1 commit into from
Jan 7, 2021
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
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