From 7408504356c3d7cd099fcf2fad008103a1dd4696 Mon Sep 17 00:00:00 2001 From: Sergey Rostov Date: Fri, 6 Jul 2018 11:35:26 +0300 Subject: [PATCH] Fix StringIndexOutOfBoundsException in KotlinConsoleFilterProvider.kt (EA-118757) --- .../kotlin/idea/run/KotlinConsoleFilterProvider.kt | 10 ++++++---- .../kotlin/idea/run/KotlinConsoleFilterTest.kt | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterProvider.kt b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterProvider.kt index 9fd68ed4dc0..e574720e2ac 100644 --- a/idea/idea-jvm/src/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterProvider.kt +++ b/idea/idea-jvm/src/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterProvider.kt @@ -40,10 +40,12 @@ class KotlinConsoleFilterProvider : ConsoleFilterProviderEx { class KotlinConsoleFilter(val project: Project, val scope: GlobalSearchScope) : Filter { override fun applyFilter(line: String, entireLength: Int): Filter.Result? { val messageSuffix = pattern.find(line) ?: return null - val pathStart = line.indexOf(":\\").takeIf { it >= 0 }?.minus(1) - ?: line.indexOf("/").takeIf { it >= 0 } - ?: return null - val path = line.substring(pathStart, messageSuffix.groups[1]!!.range.last + 1) + val pathEnd = messageSuffix.groups[1]!!.range.last + 1 + val pathWithPrefix = line.substring(0, pathEnd) + val pathStart = pathWithPrefix.indexOf(":\\").takeIf { it >= 0 }?.minus(1) + ?: pathWithPrefix.indexOf("/").takeIf { it >= 0 } + ?: return null + val path = pathWithPrefix.substring(pathStart) val lineNumber = Integer.parseInt(messageSuffix.groupValues[2]) - 1 val column = Integer.parseInt(messageSuffix.groupValues[3]) - 1 val attrs = EditorColorsManager.getInstance().globalScheme.getAttributes(CodeInsightColors.HYPERLINK_ATTRIBUTES) diff --git a/idea/tests/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterTest.kt b/idea/tests/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterTest.kt index 694947884a3..b8f357183b7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/run/KotlinConsoleFilterTest.kt @@ -41,5 +41,11 @@ class KotlinConsoleFilterTest : KotlinLightCodeInsightFixtureTestCase() { assertEquals(102, resultItem.getHighlightEndOffset()) } + fun testNoStringIndexOutOfBoundsException() { + val filter = KotlinConsoleFilter(project, GlobalSearchScope.allScope(project)) + val line = """NewOrEditTeamPageDescriptor.kt: (58, 52): The message with something/looks/like/a/path""" + assertEquals(null, filter.applyFilter(line, line.length)) + } + override fun getProjectDescriptor() = KotlinLightProjectDescriptor.INSTANCE!! } \ No newline at end of file