From 088cd4b5e394edc27629219596b753efff4b238c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 28 Sep 2018 12:34:12 +0200 Subject: [PATCH] Stop parsing argument in argfile when quote ends There are two visible effects of this change: 1) If an empty argument is passed in quotes, it will be parsed as an empty string and handled by the compiler, which will report an error later. The specific error is not very important because it's an edge case anyway; at the moment, "source file or directory not found:" is reported which is no better than the "invalid flag:" error reported by javac in the similar case 2) It's no longer possible to split an argument into several parts and quote them separately, such as: "-langu"ag"e-"ver'sio'n 1.2 No test added for this change in behavior since it's an even edgier case. Note that javac also prohibits this. #KT-27226 Fixed --- .../cli/common/arguments/preprocessCommandLineArguments.kt | 5 ++++- compiler/testData/cli/jvm/argfileWithEmptyArgument.argfile | 3 +++ compiler/testData/cli/jvm/argfileWithEmptyArgument.args | 1 + compiler/testData/cli/jvm/argfileWithEmptyArgument.out | 2 ++ .../tests/org/jetbrains/kotlin/cli/CliTestGenerated.java | 5 +++++ 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/cli/jvm/argfileWithEmptyArgument.argfile create mode 100644 compiler/testData/cli/jvm/argfileWithEmptyArgument.args create mode 100644 compiler/testData/cli/jvm/argfileWithEmptyArgument.out 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 77bdd1333c8..b763caa1bfe 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 @@ -62,7 +62,10 @@ private fun Reader.parseNextArgument(): String? { if (r.isWhitespace()) break when (r) { - DOUBLE_QUOTE, SINGLE_QUOTE -> consumeRestOfEscapedSequence(sb, r) + DOUBLE_QUOTE, SINGLE_QUOTE -> { + consumeRestOfEscapedSequence(sb, r) + return sb.toString() + } BACKSLASH -> nextChar()?.apply(sb::append) else -> sb.append(r) } diff --git a/compiler/testData/cli/jvm/argfileWithEmptyArgument.argfile b/compiler/testData/cli/jvm/argfileWithEmptyArgument.argfile new file mode 100644 index 00000000000..515d9a51c63 --- /dev/null +++ b/compiler/testData/cli/jvm/argfileWithEmptyArgument.argfile @@ -0,0 +1,3 @@ +"" +-include-runtime +-progressive diff --git a/compiler/testData/cli/jvm/argfileWithEmptyArgument.args b/compiler/testData/cli/jvm/argfileWithEmptyArgument.args new file mode 100644 index 00000000000..806ee3fd365 --- /dev/null +++ b/compiler/testData/cli/jvm/argfileWithEmptyArgument.args @@ -0,0 +1 @@ +@$TESTDATA_DIR$/argfileWithEmptyArgument.argfile diff --git a/compiler/testData/cli/jvm/argfileWithEmptyArgument.out b/compiler/testData/cli/jvm/argfileWithEmptyArgument.out new file mode 100644 index 00000000000..8ff8dfc0cbd --- /dev/null +++ b/compiler/testData/cli/jvm/argfileWithEmptyArgument.out @@ -0,0 +1,2 @@ +error: source file or directory not found: +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 52e9ddb1f1d..0860ad33261 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -66,6 +66,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/apiVersionLessThanLanguageUsingArgfile.args"); } + @TestMetadata("argfileWithEmptyArgument.args") + public void testArgfileWithEmptyArgument() throws Exception { + runTest("compiler/testData/cli/jvm/argfileWithEmptyArgument.args"); + } + @TestMetadata("argfileWithEscaping.args") public void testArgfileWithEscaping() throws Exception { runTest("compiler/testData/cli/jvm/argfileWithEscaping.args");