diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/preprocessCommandLineArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/preprocessCommandLineArguments.kt index 80c981ddd8e..77bdd1333c8 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/preprocessCommandLineArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/preprocessCommandLineArguments.kt @@ -16,8 +16,6 @@ private const val EXPERIMENTAL_ARGFILE_ARGUMENT = "-Xargfile=" private const val SINGLE_QUOTE = '\'' private const val DOUBLE_QUOTE = '"' private const val BACKSLASH = '\\' -private const val WHITESPACE = ' ' -private const val NEWLINE = '\n' /** * Performs initial preprocessing of arguments, passed to the compiler. @@ -56,13 +54,14 @@ private fun Reader.parseNextArgument(): String? { val sb = StringBuilder() var r = nextChar() - while (r != null && (r == WHITESPACE || r == NEWLINE)) { + while (r != null && r.isWhitespace()) { r = nextChar() } - loop@ while (r != null) { + while (r != null) { + if (r.isWhitespace()) break + when (r) { - WHITESPACE, NEWLINE -> break@loop DOUBLE_QUOTE, SINGLE_QUOTE -> consumeRestOfEscapedSequence(sb, r) BACKSLASH -> nextChar()?.apply(sb::append) else -> sb.append(r) diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CustomCliTest.kt b/compiler/tests/org/jetbrains/kotlin/cli/CustomCliTest.kt new file mode 100644 index 00000000000..014ca9e0860 --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/cli/CustomCliTest.kt @@ -0,0 +1,19 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.cli + +import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler +import org.jetbrains.kotlin.test.CompilerTestUtil +import org.jetbrains.kotlin.test.TestCaseWithTmpdir +import java.io.File + +class CustomCliTest : TestCaseWithTmpdir() { + fun testArgfileWithNonTrivialWhitespaces() { + val text = "-include-runtime\r\n\t\t-language-version\n\t1.2\r\n-version" + val argfile = File(tmpdir, "argfile").apply { writeText(text, Charsets.UTF_8) } + CompilerTestUtil.executeCompilerAssertSuccessful(K2JVMCompiler(), listOf("@" + argfile.absolutePath)) + } +}