From e996513044ec57617058ac30d68c2e29a0b9eedc Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 7 Sep 2018 14:26:51 +0300 Subject: [PATCH] Support single quotation marks in argfiles #KT-26122 Fixed --- .../common/arguments/preprocessCommandLineArguments.kt | 9 +++++---- compiler/testData/cli/jvm/argfileWithEscaping.argfile | 3 ++- compiler/testData/cli/jvm/argfileWithEscaping.out | 3 ++- 3 files changed, 9 insertions(+), 6 deletions(-) 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 ed7c8d4574d..d48578b6b9d 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 @@ -12,7 +12,8 @@ import java.io.Reader private const val EXPERIMENTAL_ARGFILE_ARGUMENT = "-Xargfile" -private const val QUOTATION_MARK = '"' +private const val SINGLE_QUOTE = '\'' +private const val DOUBLE_QUOTE = '"' private const val BACKSLASH = '\\' private const val WHITESPACE = ' ' private const val NEWLINE = '\n' @@ -56,7 +57,7 @@ private fun Reader.parseNextArgument(): String? { loop@ while (r != null) { when (r) { WHITESPACE, NEWLINE -> break@loop - QUOTATION_MARK -> consumeRestOfEscapedSequence(sb) + DOUBLE_QUOTE, SINGLE_QUOTE -> consumeRestOfEscapedSequence(sb, r) BACKSLASH -> nextChar()?.apply(sb::append) else -> sb.append(r) } @@ -67,9 +68,9 @@ private fun Reader.parseNextArgument(): String? { return sb.toString().takeIf { it.isNotEmpty() } } -private fun Reader.consumeRestOfEscapedSequence(sb: StringBuilder) { +private fun Reader.consumeRestOfEscapedSequence(sb: StringBuilder, quote: Char) { var ch = nextChar() - while (ch != null && ch != QUOTATION_MARK) { + while (ch != null && ch != quote) { if (ch == BACKSLASH) nextChar()?.apply(sb::append) else sb.append(ch) ch = nextChar() } diff --git a/compiler/testData/cli/jvm/argfileWithEscaping.argfile b/compiler/testData/cli/jvm/argfileWithEscaping.argfile index 50e95193f2c..4eca3c7fec4 100644 --- a/compiler/testData/cli/jvm/argfileWithEscaping.argfile +++ b/compiler/testData/cli/jvm/argfileWithEscaping.argfile @@ -1,4 +1,5 @@ --X"some escaped \" sequence \\" +-X"double \' quote ' escaped \" sequence \\" +-X'single \" quote " escaped \' sequence \\' $TESTDATA_DIR$/apiVersion.kt -d $TEMP_DIR$ -api-version 1.2 -language-version 1.3 diff --git a/compiler/testData/cli/jvm/argfileWithEscaping.out b/compiler/testData/cli/jvm/argfileWithEscaping.out index d0ea85b44de..999484b93f9 100644 --- a/compiler/testData/cli/jvm/argfileWithEscaping.out +++ b/compiler/testData/cli/jvm/argfileWithEscaping.out @@ -1,4 +1,5 @@ -warning: flag is not supported by this version of the compiler: -Xsome escaped " sequence / +warning: flag is not supported by this version of the compiler: -Xdouble ' quote ' escaped " sequence / +warning: flag is not supported by this version of the compiler: -Xsingle " quote " escaped ' sequence / compiler/testData/cli/jvm/apiVersion.kt:2:15: error: unresolved reference: sealedSubclasses ""::class.sealedSubclasses ^